Skip to content

Commit 315cbb8

Browse files
Fix
1 parent 673b3c7 commit 315cbb8

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/Reflection/Php/PhpClassReflectionExtension.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,12 @@ private function createMethod(
618618
$acceptsNamedArguments = true;
619619
$selfOutType = null;
620620
$phpDocComment = null;
621+
622+
$isPure = null;
623+
if ($this->signatureMapProvider->hasMethodMetadata($declaringClassName, $methodReflection->getName())) {
624+
$isPure = $this->signatureMapProvider->getMethodMetadata($declaringClassName, $methodReflection->getName())['hasSideEffects'];
625+
}
626+
621627
$methodSignaturesResult = $this->signatureMapProvider->getMethodSignatures($declaringClassName, $methodReflection->getName(), $methodReflection);
622628
foreach ($methodSignaturesResult as $signatureType => $methodSignatures) {
623629
if ($methodSignatures === null) {
@@ -693,6 +699,7 @@ private function createMethod(
693699

694700
$asserts = Assertions::createFromResolvedPhpDocBlock($currentResolvedPhpDoc);
695701
$acceptsNamedArguments = $currentResolvedPhpDoc->acceptsNamedArguments();
702+
$isPure ??= $currentResolvedPhpDoc->isPure();
696703

697704
$selfOutTypeTag = $currentResolvedPhpDoc->getSelfOutTag();
698705
if ($selfOutTypeTag !== null) {
@@ -727,19 +734,23 @@ private function createMethod(
727734
}
728735
}
729736

730-
if ($this->signatureMapProvider->hasMethodMetadata($declaringClassName, $methodReflection->getName())) {
731-
$hasSideEffects = TrinaryLogic::createFromBoolean($this->signatureMapProvider->getMethodMetadata($declaringClassName, $methodReflection->getName())['hasSideEffects']);
732-
} else {
733-
$hasSideEffects = TrinaryLogic::createMaybe();
737+
if ($isPure === null) {
738+
$classResolvedPhpDoc = $declaringClass->getResolvedPhpDoc();
739+
if ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsPure()) {
740+
$isPure = true;
741+
} elseif ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsImpure()) {
742+
$isPure = false;
743+
}
734744
}
745+
735746
return new NativeMethodReflection(
736747
$this->reflectionProviderProvider->getReflectionProvider(),
737748
$declaringClass,
738749
$methodReflection,
739750
$currentResolvedPhpDoc ?? null,
740751
$variantsByType['positional'],
741752
$variantsByType['named'] ?? null,
742-
$hasSideEffects,
753+
$isPure !== null ? TrinaryLogic::createFromBoolean(!$isPure) : TrinaryLogic::createMaybe(),
743754
$throwType,
744755
$asserts,
745756
$acceptsNamedArguments,

0 commit comments

Comments
 (0)