Skip to content

Commit 5241dfc

Browse files
phpstan-botclaude
andcommitted
Extract isSuperTypeOf method on ExpressionTypeHolder
Addresses review feedback: extract the certainty + isSuperTypeOf check into an ExpressionTypeHolder::isSuperTypeOf() method, mirroring the existing equals() method pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 992f476 commit 5241dfc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Analyser/ExpressionTypeHolder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ public function equals(self $other): bool
5050
return $this->type === $other->type || $this->type->equals($other->type);
5151
}
5252

53+
public function isSuperTypeOf(self $other): bool
54+
{
55+
if ($this === $other) {
56+
return true;
57+
}
58+
59+
if (!$this->certainty->equals($other->certainty)) {
60+
return false;
61+
}
62+
63+
return $this->type === $other->type || $this->type->isSuperTypeOf($other->type)->yes();
64+
}
65+
5366
public function and(self $other): self
5467
{
5568
if ($this->type === $other->type || $this->type->equals($other->type)) {

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,10 +3230,7 @@ public function filterBySpecifiedTypes(SpecifiedTypes $specifiedTypes): self
32303230
}
32313231
if (!$specifiedExpressions[$holderExprString]->equals($conditionalTypeHolder)) {
32323232
$allExact = false;
3233-
if (
3234-
!$specifiedExpressions[$holderExprString]->getCertainty()->equals($conditionalTypeHolder->getCertainty())
3235-
|| !$conditionalTypeHolder->getType()->isSuperTypeOf($specifiedExpressions[$holderExprString]->getType())->yes()
3236-
) {
3233+
if (!$conditionalTypeHolder->isSuperTypeOf($specifiedExpressions[$holderExprString])) {
32373234
$allSuperType = false;
32383235
break;
32393236
}

0 commit comments

Comments
 (0)