laminas / laminas-code

Extensions to the PHP Reflection API, static code scanning, and code generation
https://docs.laminas.dev/laminas-code/
BSD 3-Clause "New" or "Revised" License
1.85k stars 81 forks source link

MethodReflection getBody() is incomplete #96

Open titrxw opened 3 years ago

titrxw commented 3 years ago

https://github.com/laminas/laminas-code/blob/17fd2af36804f3f61788573cb70196454d6ee1d8/src/Reflection/MethodReflection.php#L230

class Test {
    public static function instance() {
        $instance = new static();

        /**
         * @var static $instance
         */
        return $instance;
    }
}

$reflectionClass = new \ReflectionClass(Test::class);
$refectionMethod = $reflectionClass->getMethod('instance');
$methodReflection = new MethodReflection($refectionMethod->getDeclaringClass()->getName(), $refectionMethod->getName());
echo $methodReflection->getBody();

The output is “$instance = new ”

Ocramius commented 3 years ago

Fairly sure that we should just deprecate that whole method: token-based parsing is a mess, and there are better tools for that nowadays.