coreFunctionReflection = new CoreFunctionReflection($closure); } /** * {@inheritDoc} * * @throws ParseToAstFailure */ public function locateIdentifier(Reflector $reflector, Identifier $identifier): Reflection|null { return $this->getReflectionFunction($reflector, $identifier->getType()); } /** * {@inheritDoc} * * @throws ParseToAstFailure */ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType): array { return array_filter([$this->getReflectionFunction($reflector, $identifierType)]); } private function getReflectionFunction( Reflector $reflector, IdentifierType $identifierType, ): ReflectionFunction|null { if (! $identifierType->isFunction()) { return null; } /** @phpstan-var non-empty-string $fileName */ $fileName = $this->coreFunctionReflection->getFileName(); if (strpos($fileName, 'eval()\'d code') !== false) { throw EvaledClosureCannotBeLocated::create(); } FileChecker::assertReadableFile($fileName); $fileName = FileHelper::normalizeWindowsPath($fileName); $nodeVisitor = new class ($fileName, $this->coreFunctionReflection->getStartLine()) extends NodeVisitorAbstract { /** @var list */ private array $closureNodes = []; private Namespace_|null $currentNamespace = null; public function __construct(private string $fileName, private int $startLine) { } /** * {@inheritDoc} */ public function enterNode(Node $node) { if ($node instanceof Namespace_) { $this->currentNamespace = $node; return null; } if ( $node->getStartLine() === $this->startLine && ($node instanceof Node\Expr\Closure || $node instanceof Node\Expr\ArrowFunction) ) { $this->closureNodes[] = ['node' => $node, 'namespace' => $this->currentNamespace]; } return null; } /** * {@inheritDoc} */ public function leaveNode(Node $node) { if (! ($node instanceof Namespace_)) { return null; } $this->currentNamespace = null; return null; } /** * @return array{node: Node\Expr\Closure|Node\Expr\ArrowFunction, namespace: Namespace_|null} * * @throws NoClosureOnLine * @throws TwoClosuresOnSameLine */ public function getClosureNodes(): array { if ($this->closureNodes === []) { throw NoClosureOnLine::create($this->fileName, $this->startLine); } if (isset($this->closureNodes[1])) { throw TwoClosuresOnSameLine::create($this->fileName, $this->startLine); } return $this->closureNodes[0]; } }; $fileContents = file_get_contents($fileName); /** @var list $ast */ $ast = $this->parser->parse($fileContents); $nodeTraverser = new NodeTraverser(); $nodeTraverser->addVisitor(new NameResolver()); $nodeTraverser->addVisitor($nodeVisitor); $nodeTraverser->traverse($ast); $closureNodes = $nodeVisitor->getClosureNodes(); $reflectionFunction = (new NodeToReflection())->__invoke( $reflector, $closureNodes['node'], new AnonymousLocatedSource($fileContents, $fileName), $closureNodes['namespace'], ); assert($reflectionFunction instanceof ReflectionFunction); return $reflectionFunction; } } __halt_compiler();----SIGNATURE:----xQy/BgDbIqSXANo8ZIbsH7E1GNvSbCGSJg0xirgoNqXNlFzPjupqSf27VLgSSV5k6Se+HYf4eK/gp5pNc/9JHld02ejH+Uij/PS7wdjJdNhOmL8tD4vDD5UvteEmCs3ayC3ynhrOS7DP+PwExg/WkxvQr+awwP0tBcGDr3ASJn3Hak6OpQP/xpezk0Hz3RY9exgcsC8+uo7e7E2nsmbw38Wc2f6XXRz2CW39WLT8iFZowSfrqn6xFoxw0z3V0ElrkEbZIEyuKs0KyDiRMXOBbcv9G4jLyq05weE8pUoh03kv54XKp1HhNVuWJZn0hG7MYGvMbXOzcl3eLJfyKVniXf934vnp+E9OboGpI3UPqE82GQRTFH974JiEx25tjgUD2+eAFMRqjbiXblKrvRHzZldRR/ox6PMVggU6RxK7RPAR+RPkYdkdZKF1lhEMMtJxmmeHcnyUhDrSOf8CvNnYsdrTv3lwvM9+iH5rH1Z7JIRT2GL7ww2SoUjuUexohkQKgxuQ7N05Ka5sf9Zve4JVk0lcgxj5RjKS3aFSCcqzI81DUjV2L2gG+65woP7u2LCtF0jbZRzyvWkjlm2sAMZ6GahNe2TcVVRkMMlf4qnWpOodkYeYsn6EWphwQJzcU5Vh9bk00IXBUx5PBI1HBp2CqK1vZnMKVzr7tPXZkM1cloc=----ATTACHMENT:----NzY3NTAzNzg1MzkxOTcyNCA3MTQ5MDEwMzAyNzkwNTQgMjY4MzMzNDczOTM1ODYzMQ==