Skip to content

Commit 0e42941

Browse files
committed
DependencyResolver - get current function reflection instead of obtaining it through ReflectionProvider
1 parent edd5c3c commit 0e42941

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/Dependency/DependencyResolver.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use PhpParser\Node\Expr\Closure;
88
use PhpParser\Node\Name;
99
use PhpParser\Node\Stmt\Foreach_;
10-
use PhpParser\Node\Stmt\Function_;
1110
use PHPStan\Analyser\Scope;
1211
use PHPStan\File\FileHelper;
1312
use PHPStan\Node\InClassMethodNode;
13+
use PHPStan\Node\InFunctionNode;
1414
use PHPStan\Reflection\ParametersAcceptorSelector;
1515
use PHPStan\Reflection\ParametersAcceptorWithPhpDocs;
1616
use PHPStan\Reflection\ReflectionProvider;
@@ -61,15 +61,9 @@ public function resolveDependencies(\PhpParser\Node $node, Scope $scope): NodeDe
6161
$this->extractFromParametersAcceptor($parametersAcceptor, $dependenciesReflections);
6262
}
6363
}
64-
} elseif ($node instanceof Function_) {
65-
$functionName = $node->name->name;
66-
if (isset($node->namespacedName)) {
67-
$functionName = (string) $node->namespacedName;
68-
}
69-
$functionNameName = new Name($functionName);
70-
if ($this->reflectionProvider->hasFunction($functionNameName, null)) {
71-
$functionReflection = $this->reflectionProvider->getFunction($functionNameName, null);
72-
64+
} elseif ($node instanceof InFunctionNode) {
65+
$functionReflection = $scope->getFunction();
66+
if ($functionReflection !== null) {
7367
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants());
7468

7569
if ($parametersAcceptor instanceof ParametersAcceptorWithPhpDocs) {

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ public function testBug3798(): void
279279
$this->assertCount(0, $errors);
280280
}
281281

282+
public function testBug3909(): void
283+
{
284+
$errors = $this->runAnalyse(__DIR__ . '/data/bug-3909.php');
285+
$this->assertCount(0, $errors);
286+
}
287+
282288
/**
283289
* @param string $file
284290
* @return \PHPStan\Analyser\Error[]
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
if (!function_exists('pg_escape_string')) {
4+
function pg_escape_string(): string {
5+
return '';
6+
}
7+
}

0 commit comments

Comments
 (0)