<commit_before><?php
namespace PHPUnitHelper\Generator;

use PHPUnitHelper\Syntax\PHPMethod;
use PHPUnitHelper\Syntax\PHPClass;
use PHPUnitHelper\Util\StringUtil;

class SkeltonGenerator
{

    const INDENT_DEPTH = 4;

    public function generateMethodSkelton(PHPMethod $method, $className = '')
    {
        $arguments = $method->getArguments();

        $argumentsCode = "";
        foreach ($arguments as $argument) {
            $type = $argument->getType();
            $name = $argument->getName();

            $default = 'null';
            if ($type == '') {
                $default = "''";
            } elseif ($type == 'array') {
                $default = 'array()';
            }
            $argumentsCode .= "$name = $default;\n";
        }

        $actualCode = '';
        if ($method->isStatic()) {

            $methodCallArgumentsCode = '';
            foreach ($method->getArguments() as $arg) {
                $argName = $arg->getName();
                if ($methodCallArgumentsCode !== '') {
                    $methodCallArgumentsCode .= ', ';
                }
                $methodCallArgumentsCode .= $argName;
            }

            $methodName = $method->getName();
            $staticMethodCall = $className . '::' . $methodName . "($methodCallArgumentsCode)";

            $actualCode .= "// \$actual = $staticMethodCall;\n";
            $actualCode = StringUtil::indent($actualCode, 4);
        }

        if ($argumentsCode) {
            $indentedArgumentsCode = StringUtil::indent($argumentsCode, self::INDENT_DEPTH);
        } else {
            $indentedArgumentsCode = '';
        }


        return
            "/**\n" .
            " * @TODO This method was generated by PHPUnitHelper\n" .
            " */\n" .
            "public function test" . ucfirst($method->getName()) . "()\n" .
            "{\n" .
            "$indentedArgumentsCode" .
            "    // \$expected =\n" .
            "$actualCode" .
            "    // \$self->assertEquals(\$expected, \$actual);\n" .
            "}\n";
    }

    public function generateClassSkelton(PHPClass $class)
    {
        $className = $class->getName();
        $methods = $class->getMethods();

        $methodCode = '';
        foreach ($methods as $method) {
            $methodCode .= $this->generateMethodSkelton($method, $className);
            if ($methodCode !== '') {
                $methodCode .= "\n";
            }
        }
        $indentedMethodCode = StringUtil::indent($methodCode, self::INDENT_DEPTH);

        $namespace = $class->getNamespace();

        $namespaceCode = '';

        if ($namespace !== '') {
            $namespaceCode = "namespace $namespace;\n\n";<commit_msg>Fixed generated namespace when namespace is global.<commit_after><?php
namespace PHPUnitHelper\Generator;

use PHPUnitHelper\Syntax\PHPMethod;
use PHPUnitHelper\Syntax\PHPClass;
use PHPUnitHelper\Util\StringUtil;

class SkeltonGenerator
{

    const INDENT_DEPTH = 4;

    public function generateMethodSkelton(PHPMethod $method, $className = '')
    {
        $arguments = $method->getArguments();

        $argumentsCode = "";
        foreach ($arguments as $argument) {
            $type = $argument->getType();
            $name = $argument->getName();

            $default = 'null';
            if ($type == '') {
                $default = "''";
            } elseif ($type == 'array') {
                $default = 'array()';
            }
            $argumentsCode .= "$name = $default;\n";
        }

        $actualCode = '';
        if ($method->isStatic()) {

            $methodCallArgumentsCode = '';
            foreach ($method->getArguments() as $arg) {
                $argName = $arg->getName();
                if ($methodCallArgumentsCode !== '') {
                    $methodCallArgumentsCode .= ', ';
                }
                $methodCallArgumentsCode .= $argName;
            }

            $methodName = $method->getName();
            $staticMethodCall = $className . '::' . $methodName . "($methodCallArgumentsCode)";

            $actualCode .= "// \$actual = $staticMethodCall;\n";
            $actualCode = StringUtil::indent($actualCode, 4);
        }

        if ($argumentsCode) {
            $indentedArgumentsCode = StringUtil::indent($argumentsCode, self::INDENT_DEPTH);
        } else {
            $indentedArgumentsCode = '';
        }


        return
            "/**\n" .
            " * @TODO This method was generated by PHPUnitHelper\n" .
            " */\n" .
            "public function test" . ucfirst($method->getName()) . "()\n" .
            "{\n" .
            "$indentedArgumentsCode" .
            "    // \$expected =\n" .
            "$actualCode" .
            "    // \$self->assertEquals(\$expected, \$actual);\n" .
            "}\n";
    }

    public function generateClassSkelton(PHPClass $class)
    {
        $className = $class->getName();
        $methods = $class->getMethods();

        $methodCode = '';
        foreach ($methods as $method) {
            $methodCode .= $this->generateMethodSkelton($method, $className);
            if ($methodCode !== '') {
                $methodCode .= "\n";
            }
        }
        $indentedMethodCode = StringUtil::indent($methodCode, self::INDENT_DEPTH);

        $namespace = $class->getNamespace();

        $namespaceCode = '';

        if ($namespace !== 'global') {
            $namespaceCode = "namespace $namespace;\n\n";
{'fraction_non_alphanumeric': 0.15563277249451354, 'fraction_numerical': 0.000731528895391368, 'mean_word_length': 1.7372372372372373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '2487790', 'n_tokens_mistral': 1493, 'n_tokens_neox': 1430, 'n_words': 268}