Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function refactorClassMethod(ClassMethod $classMethod, Scope $scope): ?C
return null;
}

$classMethodReflection = $this->reflectionResolver->resolveMethodReflectionFromClassMethod($classMethod);
$classMethodReflection = $this->reflectionResolver->resolveMethodReflectionFromClassMethod($classMethod, $scope);
if (! $classMethodReflection instanceof MethodReflection) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
return null;
}

if ($this->isInstantiable($className)) {
if ($this->isInstantiable($className, $scope)) {
$new = new New_($node->class);
return new MethodCall($new, $node->name, $node->args);
}
Expand Down Expand Up @@ -186,13 +186,13 @@ private function shouldSkip(string $methodName, string $className, StaticCall $s
return $className === $parentClassName;
}

private function isInstantiable(string $className): bool
private function isInstantiable(string $className, Scope $scope): bool
{
if (! $this->reflectionProvider->hasClass($className)) {
return false;
}

$methodReflection = $this->reflectionResolver->resolveMethodReflection($className, '__callStatic', null);
$methodReflection = $this->reflectionResolver->resolveMethodReflection($className, '__callStatic', $scope);
if ($methodReflection instanceof MethodReflection) {
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Reflection/ReflectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,15 @@ public function resolveFunctionLikeReflectionFromCall(
return $this->resolveFunctionReflectionFromFuncCall($call);
}

public function resolveMethodReflectionFromClassMethod(ClassMethod $classMethod): ?MethodReflection
public function resolveMethodReflectionFromClassMethod(ClassMethod $classMethod, Scope $scope): ?MethodReflection
{
$classReflection = $this->resolveClassReflection($classMethod);
$classReflection = $scope->getClassReflection();
if (! $classReflection instanceof ClassReflection) {
return null;
}

$className = $classReflection->getName();
$methodName = $this->nodeNameResolver->getName($classMethod);
$scope = $classMethod->getAttribute(AttributeKey::SCOPE);

return $this->resolveMethodReflection($className, $methodName, $scope);
}
Expand Down