phpowermove / php-code-generator

PHP code generator library
https://php-code-generator.readthedocs.org
Apache License 2.0
147 stars 43 forks source link

PhpParameter::fromReflection() doesn't take default parameter values #32

Closed mijohansen closed 7 years ago

mijohansen commented 8 years ago

Ill try to explain. When creating a method from reflection default parameter gets messed up.

When I have a class with a default

class SomeClass {

    public function someMethod($someOptionalParameter = null) {
    return true;
    }

}

use gossi\codegen\model\PhpClass;
use gossi\codegen\generator\CodeFileGenerator;

$phpClass = PhpClass::fromReflection(new ReflectionClass("SomeClass"));
$gen = new CodeFileGenerator();

echo $gen->generate($phpClass);

Will produce:

class SomeClass {

    /**
     * @param mixed $someOptionalParameter
     */
    public function someMethod($someOptionalParameter = ) {
        return true;
    }
}

Where as you can notice the default value is missing.

Hope this helps.

Guess the problematic area is PhpParameter::fromReflection() line 64

motia commented 8 years ago

Confirmed. But the problem is only for parameters defaulted to null. Look at my fix.

33

gossi commented 8 years ago

Confirmed. There are some more problems with default parameter values (and also property values in classes). I must address this, however not before mid october, because I need to get my thesis done.

Ref #31