Skip to content

Commit 6a2f58a

Browse files
phpstan-botclaude
andcommitted
Handle multiple ReflectionAttribute subclasses in return type resolution
Instead of returning the first matching class name from the method's return type, collect all matches and only use the result when there is exactly one unambiguous match. When there are zero or multiple matching ReflectionAttribute subclasses, fall back to the native ReflectionAttribute class. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2e13af8 commit 6a2f58a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Type/Php/ReflectionGetAttributesMethodReturnTypeExtension.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ private function resolveReflectionAttributeClassName(MethodReflection $methodRef
5454
$returnType = $methodReflection->getVariants()[0]->getReturnType();
5555
$nativeReflectionAttributeType = new ObjectType(ReflectionAttribute::class);
5656

57+
$matchedClassNames = [];
5758
foreach ($returnType->getIterableValueType()->getObjectClassNames() as $className) {
5859
if ($nativeReflectionAttributeType->isSuperTypeOf(new ObjectType($className))->yes()) {
59-
return $className;
60+
$matchedClassNames[] = $className;
6061
}
6162
}
6263

64+
if (count($matchedClassNames) === 1) {
65+
return $matchedClassNames[0];
66+
}
67+
6368
return ReflectionAttribute::class;
6469
}
6570

0 commit comments

Comments
 (0)