<commit_before><?php
if (!function_exists("readline")) {
    die("I need the readline extension to be installed and enabled!");
}

$requireFile = trim(readline("Class file: "));
if (!is_file($requireFile)) {
    die("File does not exist!". PHP_EOL);
}
require_once $requireFile;

readline_completion_function(function () {
    $classes = get_declared_classes();
    foreach($classes as &$class){
        $class = str_replace("\\",".",$class);
    }
    return $classes;
});

$class = str_replace(".", "\\", trim(readline("Class name: ")));

if (!class_exists($class)) {
    die("Class does not exist!". PHP_EOL);
}

$outfile = trim(readline("Interface file [$class.php]: "));
if (is_file($outfile)) {
    if (readline("Overwrite existing file [yes/no]? ") != "yes") {
        die("File exists, wont overwrite!". PHP_EOL);
    }
} else if (empty($outfile)) {
    $outfile = $class . ".php";
}

$rClass = new ReflectionClass($class);
$rMethods = $rClass->getMethods();
$interfaceContent = "<?php " . PHP_EOL;
$interfaceContent .= "namespace " . $rClass->getNamespaceName() . ";" . PHP_EOL;
$interfaceContent .= "interface " . $rClass->getShortName() . "{" . PHP_EOL;

foreach ($rMethods as $rMethod) {
    if ($rMethod->isPublic()) {
        $interfaceContent .= "   public function ";
        $interfaceContent .= $rMethod->getName() . "(";
        foreach ($rMethod->getParameters() as $rParameter) {
            if ($rParameter->isArray()) {
                $interfaceContent .= "array ";
            }
            if ($rParameter->isCallable()) {
                $interfaceContent .= "callable ";
            }
            if ($rParameter->getClass() != "") {
                $interfaceContent .= "\\" . $rParameter->getClass()->getName() . " ";
            }

            $interfaceContent .= "$" . $rParameter->getName();
            if ($rParameter->isDefaultValueAvailable()) {
                $interfaceContent .= " = " . (is_null($rParameter->getDefaultValue()) ? "null" : str_replace("\n",'',var_export($rParameter->getDefaultValue(), true)));
            }
            if ($rParameter != end($rMethod->getParameters())) {
                $interfaceContent .= ", ";
            }
        }
        $interfaceContent .= ");" . PHP_EOL;
    }
}
$interfaceContent .= "}" . PHP_EOL;
file_put_contents($outfile, $interfaceContent);<commit_msg>no static functions<commit_after><?php
if (!function_exists("readline")) {
    die("I need the readline extension to be installed and enabled!");
}

$requireFile = trim(readline("Class file: "));
if (!is_file($requireFile)) {
    die("File does not exist!". PHP_EOL);
}
require_once $requireFile;

readline_completion_function(function () {
    $classes = get_declared_classes();
    foreach($classes as &$class){
        $class = str_replace("\\",".",$class);
    }
    return $classes;
});

$class = str_replace(".", "\\", trim(readline("Class name: ")));

if (!class_exists($class)) {
    die("Class does not exist!". PHP_EOL);
}

$outfile = trim(readline("Interface file [$class.php]: "));
if (is_file($outfile)) {
    if (readline("Overwrite existing file [yes/no]? ") != "yes") {
        die("File exists, wont overwrite!". PHP_EOL);
    }
} else if (empty($outfile)) {
    $outfile = $class . ".php";
}

$rClass = new ReflectionClass($class);
$rMethods = $rClass->getMethods();
$interfaceName = trim(readline("Name for the interface [I{$rClass->getShortName()}]: "));
if(empty($interfaceName)){
$interfaceName = "I".$rClass->getShortName();
}
$interfaceContent = "<?php " . PHP_EOL;
$interfaceContent .= "namespace " . $rClass->getNamespaceName() . ";" . PHP_EOL;
$interfaceContent .= "interface " . $interfaceName. "{" . PHP_EOL;

foreach ($rMethods as $rMethod) {
    if ($rMethod->isPublic() && !$rMethod->isStatic()) {
        $interfaceContent .= "   public function ";
        $interfaceContent .= $rMethod->getName() . "(";
        foreach ($rMethod->getParameters() as $rParameter) {
            if ($rParameter->isArray()) {
                $interfaceContent .= "array ";
            }
            if ($rParameter->isCallable()) {
                $interfaceContent .= "callable ";
            }
            if ($rParameter->getClass() != "") {
                $interfaceContent .= "\\" . $rParameter->getClass()->getName() . " ";
            }

            $interfaceContent .= "$" . $rParameter->getName();
            if ($rParameter->isDefaultValueAvailable()) {
                $interfaceContent .= " = " . (is_null($rParameter->getDefaultValue()) ? "null" : str_replace("\n",'',var_export($rParameter->getDefaultValue(), true)));
            }
            if ($rParameter != end($rMethod->getParameters())) {
                $interfaceContent .= ", ";
            }
        }
        $interfaceContent .= ");" . PHP_EOL;
    }
}
$interfaceContent .= "}" . PHP_EOL;
file_put_contents($outfile, $interfaceContent);

{'fraction_non_alphanumeric': 0.19155910674042204, 'fraction_numerical': 0.0, 'mean_word_length': 2.9087269815852683, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2693495', 'n_tokens_mistral': 1469, 'n_tokens_neox': 1453, 'n_words': 273}