Skip to content

Commit

Permalink
[NodeTypeResolver] Handle namespaced function call name on NodeTypeRe…
Browse files Browse the repository at this point in the history
…solver (#6564)

* [NodeTypeResolver] Handle namespaced function call name on NodeTypeResolver

* fix
  • Loading branch information
samsonasik authored Dec 12, 2024
1 parent 184eb2e commit 0bfd08d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/NodeTypeResolver/NodeTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use Rector\Configuration\RenamedClassesDataCollector;
use Rector\Exception\ShouldNotHappenException;
use Rector\NodeAnalyzer\ClassAnalyzer;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Contract\NodeTypeResolverAwareInterface;
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -76,6 +77,7 @@ public function __construct(
private readonly ReflectionProvider $reflectionProvider,
private readonly AccessoryNonEmptyStringTypeCorrector $accessoryNonEmptyStringTypeCorrector,
private readonly RenamedClassesDataCollector $renamedClassesDataCollector,
private readonly NodeNameResolver $nodeNameResolver,
iterable $nodeTypeResolvers
) {
foreach ($nodeTypeResolvers as $nodeTypeResolver) {
Expand Down Expand Up @@ -567,11 +569,12 @@ private function resolveNativeTypeWithBuiltinMethodCallFallback(Expr $expr, Scop
return $scope->getNativeType($expr);
}

if (! $this->reflectionProvider->hasFunction($expr->name, $scope)) {
$functionName = new Name((string) $this->nodeNameResolver->getName($expr));
if (! $this->reflectionProvider->hasFunction($functionName, $scope)) {
return $scope->getNativeType($expr);
}

$functionReflection = $this->reflectionProvider->getFunction($expr->name, $scope);
$functionReflection = $this->reflectionProvider->getFunction($functionName, $scope);
if (! $functionReflection instanceof NativeFunctionReflection) {
return $scope->getNativeType($expr);
}
Expand Down
6 changes: 4 additions & 2 deletions src/PhpParser/AstResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Name;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Class_;
Expand Down Expand Up @@ -398,11 +399,12 @@ private function resolveFunctionFromFuncCall(FuncCall $funcCall, Scope $scope):
return null;
}

if (! $this->reflectionProvider->hasFunction($funcCall->name, $scope)) {
$functionName = new Name((string) $this->nodeNameResolver->getName($funcCall));
if (! $this->reflectionProvider->hasFunction($functionName, $scope)) {
return null;
}

$functionReflection = $this->reflectionProvider->getFunction($funcCall->name, $scope);
$functionReflection = $this->reflectionProvider->getFunction($functionName, $scope);
return $this->resolveFunctionFromFunctionReflection($functionReflection);
}
}
5 changes: 3 additions & 2 deletions src/Reflection/ReflectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ private function resolveFunctionReflectionFromFuncCall(
return null;
}

if ($this->reflectionProvider->hasFunction($funcCall->name, $scope)) {
return $this->reflectionProvider->getFunction($funcCall->name, $scope);
$functionName = new Name((string) $this->nodeNameResolver->getName($funcCall));
if ($this->reflectionProvider->hasFunction($functionName, $scope)) {
return $this->reflectionProvider->getFunction($functionName, $scope);
}

return null;
Expand Down

0 comments on commit 0bfd08d

Please sign in to comment.