diff --git a/src/SourceLocator/Ast/FindReflectionsInTree.php b/src/SourceLocator/Ast/FindReflectionsInTree.php index 145d0279d..be918e04d 100644 --- a/src/SourceLocator/Ast/FindReflectionsInTree.php +++ b/src/SourceLocator/Ast/FindReflectionsInTree.php @@ -134,7 +134,14 @@ public function leaveNode(Node $node) } } - if ($this->identifierType->isFunction() && $node instanceof Node\Stmt\Function_) { + if ( + $this->identifierType->isFunction() + && ( + $node instanceof Node\Stmt\Function_ + || $node instanceof Node\Expr\Closure + || $node instanceof Node\Expr\ArrowFunction + ) + ) { $this->reflections[] = $this->astConversionStrategy->__invoke($this->reflector, $node, $this->locatedSource, $this->currentNamespace); } diff --git a/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php b/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php index 37c36b833..f2ab2fada 100644 --- a/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php +++ b/test/unit/SourceLocator/Ast/FindReflectionsInTreeTest.php @@ -139,7 +139,18 @@ public function testInvokeCallsReflectNodesForNamespacedClassType(string $classT ); } - public function testInvokeCallsReflectNodesForFunction(): void + /** @return list */ + public static function dataFunctionSources(): array + { + return [ + [' "foo";', 'arrow_function'], + ]; + } + + #[DataProvider('dataFunctionSources')] + public function testInvokeCallsReflectNodesForFunction(string $source, string $name): void { $strategy = $this->createMock(NodeToReflection::class); @@ -150,7 +161,7 @@ public function testInvokeCallsReflectNodesForFunction(): void ->willReturn($mockReflection); $reflector = $this->createMock(Reflector::class); - $locatedSource = new LocatedSource('