Skip to content

Commit b256d50

Browse files
committed
[BCB] Changed TemplateType::isValidVariance() return type to IsSuperTypeOfResult
1 parent 244337e commit b256d50

File tree

5 files changed

+16
-18
lines changed

5 files changed

+16
-18
lines changed

UPGRADING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ Instead of `AccessoryArrayListType::intersectWith($type)`, do `TypeCombinator::i
313313
* `PHPStan\Node\Printer\Printer` no longer autowired as `PhpParser\PrettyPrinter\Standard`, use `PHPStan\Node\Printer\Printer` in the typehint
314314
* Remove `Type::acceptsWithReason()`, `Type:accepts()` return type changed from `TrinaryLogic` to [`AcceptsResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.AcceptsResult.html)
315315
* Remove `CompoundType::isAcceptedWithReasonBy()`, `CompoundType::isAcceptedBy()` return type changed from `TrinaryLogic` to [`AcceptsResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.AcceptsResult.html)
316+
* Remove `TemplateType::isValidVarianceWithReason()`, changed `TemplateType::isValidVariance()` return type to `IsSuperTypeOfResult`
316317
* `RuleLevelHelper::accepts()` return type changed from `bool` to [`RuleLevelHelperAcceptsResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.AcceptsResult.html)
317318
* Changes around `ClassConstantReflection`
318319
* Class `ClassConstantReflection` removed from BC promise, renamed to `RealClassConstantReflection`

src/Type/Generic/GenericObjectType.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,9 @@ private function isSuperTypeOfInternal(Type $type, bool $acceptsContext): IsSupe
190190
$thisVariance = $this->variances[$i] ?? TemplateTypeVariance::createInvariant();
191191
$ancestorVariance = $ancestor->variances[$i] ?? TemplateTypeVariance::createInvariant();
192192
if (!$thisVariance->invariant()) {
193-
$result = $thisVariance->isValidVariance($templateType, $this->types[$i], $ancestor->types[$i]);
194-
$results[] = new IsSuperTypeOfResult($result->result, $result->reasons);
193+
$results[] = $thisVariance->isValidVariance($templateType, $this->types[$i], $ancestor->types[$i]);
195194
} else {
196-
$result = $templateType->isValidVariance($this->types[$i], $ancestor->types[$i]);
197-
$results[] = new IsSuperTypeOfResult($result->result, $result->reasons);
195+
$results[] = $templateType->isValidVariance($this->types[$i], $ancestor->types[$i]);
198196
}
199197

200198
$results[] = IsSuperTypeOfResult::createFromBoolean($thisVariance->validPosition($ancestorVariance));

src/Type/Generic/TemplateType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace PHPStan\Type\Generic;
44

5-
use PHPStan\Type\AcceptsResult;
65
use PHPStan\Type\CompoundType;
6+
use PHPStan\Type\IsSuperTypeOfResult;
77
use PHPStan\Type\Type;
88

99
/** @api */
@@ -21,7 +21,7 @@ public function toArgument(): TemplateType;
2121

2222
public function isArgument(): bool;
2323

24-
public function isValidVariance(Type $a, Type $b): AcceptsResult;
24+
public function isValidVariance(Type $a, Type $b): IsSuperTypeOfResult;
2525

2626
public function getVariance(): TemplateTypeVariance;
2727

src/Type/Generic/TemplateTypeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function toArgument(): TemplateType
9292
);
9393
}
9494

95-
public function isValidVariance(Type $a, Type $b): AcceptsResult
95+
public function isValidVariance(Type $a, Type $b): IsSuperTypeOfResult
9696
{
9797
return $this->variance->isValidVariance($this, $a, $b);
9898
}

src/Type/Generic/TemplateTypeVariance.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
66
use PHPStan\ShouldNotHappenException;
77
use PHPStan\TrinaryLogic;
8-
use PHPStan\Type\AcceptsResult;
98
use PHPStan\Type\BenevolentUnionType;
109
use PHPStan\Type\IsSuperTypeOfResult;
1110
use PHPStan\Type\MixedType;
@@ -127,30 +126,30 @@ public function compose(self $other): self
127126
return $other;
128127
}
129128

130-
public function isValidVariance(TemplateType $templateType, Type $a, Type $b): AcceptsResult
129+
public function isValidVariance(TemplateType $templateType, Type $a, Type $b): IsSuperTypeOfResult
131130
{
132131
if ($b instanceof NeverType) {
133-
return AcceptsResult::createYes();
132+
return IsSuperTypeOfResult::createYes();
134133
}
135134

136135
if ($a instanceof MixedType && !$a instanceof TemplateType) {
137-
return AcceptsResult::createYes();
136+
return IsSuperTypeOfResult::createYes();
138137
}
139138

140139
if ($a instanceof BenevolentUnionType) {
141140
if (!$a->isSuperTypeOf($b)->no()) {
142-
return AcceptsResult::createYes();
141+
return IsSuperTypeOfResult::createYes();
143142
}
144143
}
145144

146145
if ($b instanceof BenevolentUnionType) {
147146
if (!$b->isSuperTypeOf($a)->no()) {
148-
return AcceptsResult::createYes();
147+
return IsSuperTypeOfResult::createYes();
149148
}
150149
}
151150

152151
if ($b instanceof MixedType && !$b instanceof TemplateType) {
153-
return AcceptsResult::createYes();
152+
return IsSuperTypeOfResult::createYes();
154153
}
155154

156155
if ($this->invariant()) {
@@ -169,19 +168,19 @@ public function isValidVariance(TemplateType $templateType, Type $a, Type $b): A
169168
}
170169
}
171170

172-
return new AcceptsResult(TrinaryLogic::createFromBoolean($result), $reasons);
171+
return new IsSuperTypeOfResult(TrinaryLogic::createFromBoolean($result), $reasons);
173172
}
174173

175174
if ($this->covariant()) {
176-
return $a->isSuperTypeOfWithReason($b)->toAcceptsResult();
175+
return $a->isSuperTypeOfWithReason($b);
177176
}
178177

179178
if ($this->contravariant()) {
180-
return $b->isSuperTypeOfWithReason($a)->toAcceptsResult();
179+
return $b->isSuperTypeOfWithReason($a);
181180
}
182181

183182
if ($this->bivariant()) {
184-
return AcceptsResult::createYes();
183+
return IsSuperTypeOfResult::createYes();
185184
}
186185

187186
throw new ShouldNotHappenException();

0 commit comments

Comments
 (0)