Skip to content

Commit

Permalink
DependencyResolver - get current function reflection instead of obtai…
Browse files Browse the repository at this point in the history
…ning it through ReflectionProvider
  • Loading branch information
ondrejmirtes committed Oct 2, 2020
1 parent edd5c3c commit 0e42941
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Dependency/DependencyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Analyser/data/bug-3909.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

if (!function_exists('pg_escape_string')) {
function pg_escape_string(): string {
return '';
}
}

0 comments on commit 0e42941

Please sign in to comment.