From eee4f71c2b3fc7ae46896069798a8d9c6fe2f077 Mon Sep 17 00:00:00 2001 From: fix-issue-bot Date: Wed, 27 May 2026 06:45:07 +0200 Subject: [PATCH] fix: use native method lookup in ParentClassMethodNodeResolver (fixes #263) PHPStan's hasMethod()/getMethod() include methods reported by class reflection extensions (e.g. Doctrine's magic findOneBy* finders). When such an extension reports hasMethod() = true for a method like findOneBySlug() but the method isn't actually native, getMethod() throws MissingMethodFromReflectionException, crashing NoReferenceRule. Switching to hasNativeMethod()/getNativeMethod() restricts the lookup to real source methods, which is what we actually need since the resolver's downstream consumer parses the method's AST node. Co-Authored-By: Claude Opus 4.7 --- src/ParentClassMethodNodeResolver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ParentClassMethodNodeResolver.php b/src/ParentClassMethodNodeResolver.php index 8cc260c3e..45a68ecf9 100644 --- a/src/ParentClassMethodNodeResolver.php +++ b/src/ParentClassMethodNodeResolver.php @@ -23,12 +23,13 @@ public function resolveParentClassMethod(Scope $scope, string $methodName): ?Cla $parentClassReflections = $this->getParentClassReflections($scope); foreach ($parentClassReflections as $parentClassReflection) { - if (! $parentClassReflection->hasMethod($methodName)) { + // native only: avoid magic methods from extensions (e.g. Doctrine findOneBy*) which can be reported by hasMethod() but throw on getMethod() + if (! $parentClassReflection->hasNativeMethod($methodName)) { continue; } $classReflection = $this->reflectionProvider->getClass($parentClassReflection->getName()); - $parentMethodReflection = $classReflection->getMethod($methodName, $scope); + $parentMethodReflection = $classReflection->getNativeMethod($methodName); return $this->reflectionParser->parseMethodReflection($parentMethodReflection); }