diff --git a/src/Dependency/DependencyResolver.php b/src/Dependency/DependencyResolver.php index 002b73f03c..80440237e4 100644 --- a/src/Dependency/DependencyResolver.php +++ b/src/Dependency/DependencyResolver.php @@ -7,10 +7,10 @@ use PhpParser\Node\Expr\Closure; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Foreach_; -use PhpParser\Node\Stmt\Function_; use PHPStan\Analyser\Scope; use PHPStan\File\FileHelper; use PHPStan\Node\InClassMethodNode; +use PHPStan\Node\InFunctionNode; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Reflection\ParametersAcceptorWithPhpDocs; use PHPStan\Reflection\ReflectionProvider; @@ -61,15 +61,9 @@ public function resolveDependencies(\PhpParser\Node $node, Scope $scope): NodeDe $this->extractFromParametersAcceptor($parametersAcceptor, $dependenciesReflections); } } - } elseif ($node instanceof Function_) { - $functionName = $node->name->name; - if (isset($node->namespacedName)) { - $functionName = (string) $node->namespacedName; - } - $functionNameName = new Name($functionName); - if ($this->reflectionProvider->hasFunction($functionNameName, null)) { - $functionReflection = $this->reflectionProvider->getFunction($functionNameName, null); - + } elseif ($node instanceof InFunctionNode) { + $functionReflection = $scope->getFunction(); + if ($functionReflection !== null) { $parametersAcceptor = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants()); if ($parametersAcceptor instanceof ParametersAcceptorWithPhpDocs) { diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index afbda2777d..6ce6e7cdcc 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -279,6 +279,12 @@ public function testBug3798(): void $this->assertCount(0, $errors); } + public function testBug3909(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-3909.php'); + $this->assertCount(0, $errors); + } + /** * @param string $file * @return \PHPStan\Analyser\Error[] diff --git a/tests/PHPStan/Analyser/data/bug-3909.php b/tests/PHPStan/Analyser/data/bug-3909.php new file mode 100644 index 0000000000..3dd72bcf2f --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-3909.php @@ -0,0 +1,7 @@ +