Skip to content

Commit dbef03c

Browse files
phpstan-botclaude
andcommitted
Move class-level isPure check outside the resolvedPhpDoc null check
The class-level purity check (areAllMethodsPure/areAllMethodsImpure) reads from phpDocBlockClassReflection->getResolvedPhpDoc(), not from the method's resolvedPhpDoc. It should run even when resolvedPhpDoc is null (e.g. constructors with promoted properties and no method doc). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 461aa13 commit dbef03c

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -906,22 +906,6 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
906906
$isInternal = $resolvedPhpDoc->isInternal();
907907
$isFinal = $resolvedPhpDoc->isFinal();
908908
$isPure ??= $resolvedPhpDoc->isPure();
909-
if ($isPure === null) {
910-
$classResolvedPhpDoc = $phpDocBlockClassReflection->getResolvedPhpDoc();
911-
if ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsPure()) {
912-
if (
913-
strtolower($methodReflection->getName()) === '__construct'
914-
|| (
915-
($phpDocReturnType === null || !$phpDocReturnType->isVoid()->yes())
916-
&& !$nativeReturnType->isVoid()->yes()
917-
)
918-
) {
919-
$isPure = true;
920-
}
921-
} elseif ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsImpure()) {
922-
$isPure = false;
923-
}
924-
}
925909
$asserts = Assertions::createFromResolvedPhpDocBlock($resolvedPhpDoc);
926910
$acceptsNamedArguments = $resolvedPhpDoc->acceptsNamedArguments();
927911
$selfOutType = $resolvedPhpDoc->getSelfOutTag() !== null ? $resolvedPhpDoc->getSelfOutTag()->getType() : null;
@@ -930,6 +914,23 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
930914
}
931915
}
932916

917+
if ($isPure === null) {
918+
$classResolvedPhpDoc = $phpDocBlockClassReflection->getResolvedPhpDoc();
919+
if ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsPure()) {
920+
if (
921+
strtolower($methodReflection->getName()) === '__construct'
922+
|| (
923+
($phpDocReturnType === null || !$phpDocReturnType->isVoid()->yes())
924+
&& !$nativeReturnType->isVoid()->yes()
925+
)
926+
) {
927+
$isPure = true;
928+
}
929+
} elseif ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsImpure()) {
930+
$isPure = false;
931+
}
932+
}
933+
933934
foreach ($phpDocParameterTypes as $paramName => $paramType) {
934935
$phpDocParameterTypes[$paramName] = TemplateTypeHelper::resolveTemplateTypes(
935936
$paramType,

0 commit comments

Comments
 (0)