gossi\codegen\model\PhpFunction::fromReflection PHP Method

fromReflection() public static method

Creates a PHP function from reflection
Deprecation: will be removed in version 0.5
public static fromReflection ( ReflectionFunction $ref ) : PhpFunction
$ref ReflectionFunction
return PhpFunction
    public static function fromReflection(\ReflectionFunction $ref)
    {
        $function = self::create($ref->name)->setReferenceReturned($ref->returnsReference())->setBody(ReflectionUtils::getFunctionBody($ref));
        $docblock = new Docblock($ref);
        $function->setDocblock($docblock);
        $function->setDescription($docblock->getShortDescription());
        $function->setLongDescription($docblock->getLongDescription());
        foreach ($ref->getParameters() as $refParam) {
            assert($refParam instanceof \ReflectionParameter);
            // hmm - assert here?
            $param = PhpParameter::fromReflection($refParam);
            $function->addParameter($param);
        }
        return $function;
    }

Usage Example

    public function testFromReflection()
    {
        $doc = new Docblock('/**
 * Makes foo with bar
 * 
 * @param string $baz
 * @return string
 */');
        $function = new PhpFunction('wurst');
        $function->addParameter(PhpParameter::create('baz')->setDefaultValue(null)->setType('string'))->setBody('return \'wurst\';')->setDocblock($doc)->setDescription($doc->getShortDescription())->setLongDescription($doc->getLongDescription());
        $this->assertEquals($function, PhpFunction::fromReflection(new \ReflectionFunction('wurst')));
    }