diff --git a/src/PhpParser/AstResolver.php b/src/PhpParser/AstResolver.php index 3d4f8810a1b..00f8015d484 100644 --- a/src/PhpParser/AstResolver.php +++ b/src/PhpParser/AstResolver.php @@ -139,6 +139,11 @@ public function resolveClassMethodFromCall(MethodCall|StaticCall|NullsafeMethodC return $this->resolveClassMethod($className, MethodName::CONSTRUCT); } + $methodName = $this->nodeNameResolver->getName($call->name); + if ($methodName === null) { + return null; + } + $callerStaticType = ($call instanceof MethodCall || $call instanceof NullsafeMethodCall) ? $this->nodeTypeResolver->getType($call->var) : $this->nodeTypeResolver->getType($call->class); @@ -148,11 +153,6 @@ public function resolveClassMethodFromCall(MethodCall|StaticCall|NullsafeMethodC return null; } - $methodName = $this->nodeNameResolver->getName($call->name); - if ($methodName === null) { - return null; - } - return $this->resolveClassMethod($className, $methodName); } diff --git a/src/Reflection/ReflectionResolver.php b/src/Reflection/ReflectionResolver.php index d70e1a9dfbf..3e333f007bb 100644 --- a/src/Reflection/ReflectionResolver.php +++ b/src/Reflection/ReflectionResolver.php @@ -138,6 +138,11 @@ public function resolveMethodReflection(string $className, string $methodName, ? public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ?MethodReflection { + $methodName = $this->nodeNameResolver->getName($staticCall->name); + if ($methodName === null) { + return null; + } + $objectType = $this->nodeTypeResolver->getType($staticCall->class); if ($objectType instanceof ShortenedObjectType || $objectType instanceof AliasedObjectType) { @@ -148,11 +153,6 @@ public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ? $classNames = $objectType->getObjectClassNames(); } - $methodName = $this->nodeNameResolver->getName($staticCall->name); - if ($methodName === null) { - return null; - } - $scope = $staticCall->getAttribute(AttributeKey::SCOPE); foreach ($classNames as $className) { @@ -167,20 +167,18 @@ public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall): ? public function resolveMethodReflectionFromMethodCall(MethodCall $methodCall): ?MethodReflection { - $callerType = $this->nodeTypeResolver->getType($methodCall->var); + $methodName = $this->nodeNameResolver->getName($methodCall->name); + if ($methodName === null) { + return null; + } + $callerType = $this->nodeTypeResolver->getType($methodCall->var); if ($callerType instanceof BenevolentUnionType) { $callerType = TypeCombinator::removeFalsey($callerType); } $className = ClassNameFromObjectTypeResolver::resolve($callerType); if ($className === null) { - - return null; - } - - $methodName = $this->nodeNameResolver->getName($methodCall->name); - if ($methodName === null) { return null; }