BetterReflection\Reflection\ReflectionFunctionAbstract::setBodyFromClosure PHP Method

setBodyFromClosure() public method

Override the method or function's body of statements with an entirely new body of statements within the reflection.
public setBodyFromClosure ( Closure $newBody )
$newBody Closure
    public function setBodyFromClosure(\Closure $newBody)
    {
        $closureData = (new AstAnalyzer())->analyze($newBody);
        if (!isset($closureData['ast']) || !$closureData['ast'] instanceof ClosureNode) {
            throw new Exception\ClosureAstExtractionFailure('Failed to extract AST from closure - AST data not returned by AstAnalyzer');
        }
        $this->node->stmts = $closureData['ast']->stmts;
    }