Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6723fac

Browse files
Try
1 parent 257216b commit 6723fac

File tree

4 files changed

+29
-46
lines changed

4 files changed

+29
-46
lines changed

‎src/PhpDoc/PhpDocNodeResolver.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,12 @@ public function resolveIsImpure(PhpDocNode $phpDocNode): bool
705705
return false;
706706
}
707707

708-
public function resolveAllMethodsArePure(PhpDocNode $phpDocNode): bool
708+
public function resolveAllMethodsPure(PhpDocNode $phpDocNode): bool
709709
{
710710
return count($phpDocNode->getTagsByName('@phpstan-all-methods-pure')) > 0;
711711
}
712712

713-
public function resolveAllMethodsAreImpure(PhpDocNode $phpDocNode): bool
713+
public function resolveAllMethodsImpure(PhpDocNode $phpDocNode): bool
714714
{
715715
return count($phpDocNode->getTagsByName('@phpstan-all-methods-impure')) > 0;
716716
}

‎src/PhpDoc/ResolvedPhpDocBlock.php‎

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,9 @@ final class ResolvedPhpDocBlock
139139
/** @var bool|'notLoaded'|null */
140140
private bool|string|null $isPure = 'notLoaded';
141141

142-
/** @var bool|'notLoaded'|null */
143-
private bool|string|null $defaultMethodPurity = 'notLoaded';
142+
private ?bool $areAllMethodsPure = null;
143+
144+
private ?bool $areAllMethodsImpure = null;
144145

145146
private ?bool $isReadOnly = null;
146147

@@ -236,7 +237,8 @@ public static function createEmpty(): self
236237
$self->isInternal = false;
237238
$self->isFinal = false;
238239
$self->isPure = null;
239-
$self->defaultMethodPurity = null;
240+
$self->areAllMethodsPure = false;
241+
$self->areAllMethodsImpure = false;
240242
$self->isReadOnly = false;
241243
$self->isImmutable = false;
242244
$self->isAllowedPrivateMutation = false;
@@ -302,7 +304,8 @@ public function merge(array $parents, array $parentPhpDocBlocks): self
302304
$result->isInternal = $this->isInternal();
303305
$result->isFinal = $this->isFinal();
304306
$result->isPure = self::mergePureTags($this->isPure(), $parents);
305-
$result->defaultMethodPurity = $this->getDefaultMethodPurity();
307+
$result->areAllMethodsPure = $this->areAllMethodsPure();
308+
$result->areAllMethodsImpure = $this->areAllMethodsImpure();
306309
$result->isReadOnly = $this->isReadOnly();
307310
$result->isImmutable = $this->isImmutable();
308311
$result->isAllowedPrivateMutation = $this->isAllowedPrivateMutation();
@@ -423,7 +426,6 @@ public function changeParameterNamesByMapping(array $parameterNameMapping): self
423426
$self->isInternal = $this->isInternal;
424427
$self->isFinal = $this->isFinal;
425428
$self->isPure = $this->isPure;
426-
$self->defaultMethodPurity = $this->defaultMethodPurity;
427429

428430
return $self;
429431
}
@@ -833,29 +835,18 @@ public function isPure(): ?bool
833835
return $this->isPure;
834836
}
835837

836-
public function getDefaultMethodPurity(): ?bool
838+
public function areAllMethodsPure(): bool
837839
{
838-
if ($this->defaultMethodPurity === 'notLoaded') {
839-
$pure = $this->phpDocNodeResolver->resolveAllMethodsArePure(
840-
$this->phpDocNode,
841-
);
842-
if ($pure) {
843-
$this->defaultMethodPurity = true;
844-
return $this->defaultMethodPurity;
845-
}
846-
847-
$impure = $this->phpDocNodeResolver->resolveAllMethodsAreImpure(
848-
$this->phpDocNode,
849-
);
850-
if ($impure) {
851-
$this->defaultMethodPurity = false;
852-
return $this->defaultMethodPurity;
853-
}
854-
855-
$this->defaultMethodPurity = null;
856-
}
840+
return $this->areAllMethodsPure ??= $this->phpDocNodeResolver->resolveAllMethodsPure(
841+
$this->phpDocNode,
842+
);
843+
}
857844

858-
return $this->defaultMethodPurity;
845+
public function areAllMethodsImpure(): bool
846+
{
847+
return $this->areAllMethodsImpure ??= $this->phpDocNodeResolver->resolveAllMethodsImpure(
848+
$this->phpDocNode,
849+
);
859850
}
860851

861852
public function isReadOnly(): bool

‎src/Reflection/ClassReflection.php‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ final class ClassReflection
113113

114114
private ?bool $hasConsistentConstructor = null;
115115

116-
/** @var bool|'notLoaded'|null */
117-
private bool|string|null $defaultMethodPurity = 'notLoaded';
118-
119116
private ?bool $acceptsNamedArguments = null;
120117

121118
private ?TemplateTypeMap $templateTypeMap = null;
@@ -1495,20 +1492,6 @@ public function hasConsistentConstructor(): bool
14951492
return $this->hasConsistentConstructor;
14961493
}
14971494

1498-
public function getDefaultMethodPurity(): ?bool
1499-
{
1500-
if ($this->defaultMethodPurity === 'notLoaded') {
1501-
$resolvedPhpDoc = $this->getResolvedPhpDoc();
1502-
if ($resolvedPhpDoc === null) {
1503-
$this->defaultMethodPurity = null;
1504-
} else {
1505-
$this->defaultMethodPurity = $resolvedPhpDoc->getDefaultMethodPurity();
1506-
}
1507-
}
1508-
1509-
return $this->defaultMethodPurity;
1510-
}
1511-
15121495
public function acceptsNamedArguments(): bool
15131496
{
15141497
if ($this->acceptsNamedArguments === null) {

‎src/Reflection/Php/PhpClassReflectionExtension.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,16 @@ public function createUserlandMethodReflection(ClassReflection $fileDeclaringCla
892892
}
893893
}
894894

895-
$isPure ??= $resolvedPhpDoc->isPure() ?? $phpDocBlockClassReflection->getDefaultMethodPurity();
895+
$isPure ??= $resolvedPhpDoc->isPure();
896+
if ($isPure === null) {
897+
$classResolvedPhpDoc = $phpDocBlockClassReflection->getResolvedPhpDoc();
898+
if ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsPure()) {
899+
$isPure = true;
900+
} elseif ($classResolvedPhpDoc !== null && $classResolvedPhpDoc->areAllMethodsImpure()) {
901+
$isPure = false;
902+
}
903+
}
904+
896905
$asserts = Assertions::createFromResolvedPhpDocBlock($resolvedPhpDoc);
897906
$acceptsNamedArguments = $resolvedPhpDoc->acceptsNamedArguments();
898907
$selfOutType = $resolvedPhpDoc->getSelfOutTag() !== null ? $resolvedPhpDoc->getSelfOutTag()->getType() : null;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /