diff --git a/rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php b/rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php index 08fbc17de42..f03ef195ad4 100644 --- a/rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php +++ b/rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php @@ -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; } diff --git a/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php b/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php index ba07b6c55ca..df98f31644c 100644 --- a/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php +++ b/rules/Php70/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php @@ -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); } @@ -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; } diff --git a/src/Reflection/ReflectionResolver.php b/src/Reflection/ReflectionResolver.php index 9fe9a2d49de..40a12daa185 100644 --- a/src/Reflection/ReflectionResolver.php +++ b/src/Reflection/ReflectionResolver.php @@ -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); }