Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NodeTypeResolver] Handle namespaced function call name on NodeTypeResolver #6564

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading