src/Reflection/ReflectionFunctionAbstract.php
public function setBodyFromClosure(Closure $newBody) : void
    {
        /** @var self $closureReflection */
        $closureReflection = (new ClosureSourceLocator($newBody, $this->loadStaticParser()))->locateIdentifier(
            $this->reflector,
            new Identifier(self::CLOSURE_NAME, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION))
        );

        /** @var Node\Stmt\Function_ $functionNode */
        $functionNode = $closureReflection->getNode();

        $this->node->stmts = $functionNode->stmts;
    }
public function setBodyFromClosure(Closure $newBody) : void
    {
        /** @var self $closureReflection */
        $closureReflection = (new ClosureSourceLocator($newBody, $this->loadStaticParser()))->locateIdentifier(
            $this->reflector,
            new Identifier(self::CLOSURE_NAME, new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION))
        );

        /** @var Node\Stmt\Function_ $functionNode */
        $functionNode = $closureReflection->getNode();

        $this->node->stmts = $functionNode->stmts;
    }
Override the method or function's body of statements with an entirely new
body of statements within the reflection.

@throws ParseToAstFailure
@throws InvalidIdentifierName

@example
$reflectionFunction->setBodyFromClosure(function () { return true; });