Skip to content

Commit f81bc5d

Browse files
committed
[BCB] Remove Type::isSuperTypeOfWithReason(), Type::isSuperTypeOf() return type changed to IsSuperTypeOfResult
1 parent 8bd940b commit f81bc5d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+231
-586
lines changed

Diff for: UPGRADING.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,9 @@ 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`
316+
Remove `Type::isSuperTypeOfWithReason()`, `Type:isSuperTypeOf()` return type changed from `TrinaryLogic` to [`IsSuperTypeOfResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.IsSuperTypeOfResult.html)
317+
* Remove `CompoundType::isSubTypeOfWithReasonBy()`, `CompoundType::isSubTypeOf()` return type changed from `TrinaryLogic` to [`IsSuperTypeOfResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.IsSuperTypeOfResult.html)
318+
* Remove `TemplateType::isValidVarianceWithReason()`, changed `TemplateType::isValidVariance()` return type to [`IsSuperTypeOfResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.IsSuperTypeOfResult.html)
317319
* `RuleLevelHelper::accepts()` return type changed from `bool` to [`RuleLevelHelperAcceptsResult`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.AcceptsResult.html)
318320
* Changes around `ClassConstantReflection`
319321
* Class `ClassConstantReflection` removed from BC promise, renamed to `RealClassConstantReflection`

Diff for: src/Analyser/TypeSpecifier.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ private function narrowUnionByArraySize(FuncCall $countFuncCall, UnionType $argT
963963
$isNormalCount = TrinaryLogic::createYes();
964964
} else {
965965
$mode = $scope->getType($countFuncCall->getArgs()[1]->value);
966-
$isNormalCount = (new ConstantIntegerType(COUNT_NORMAL))->isSuperTypeOf($mode)->or($argType->getIterableValueType()->isArray()->negate());
966+
$isNormalCount = (new ConstantIntegerType(COUNT_NORMAL))->isSuperTypeOf($mode)->result->or($argType->getIterableValueType()->isArray()->negate());
967967
}
968968

969969
if (
@@ -1007,7 +1007,7 @@ private function turnListIntoConstantArray(FuncCall $countFuncCall, Type $type,
10071007
$isNormalCount = TrinaryLogic::createYes();
10081008
} else {
10091009
$mode = $scope->getType($countFuncCall->getArgs()[1]->value);
1010-
$isNormalCount = (new ConstantIntegerType(COUNT_NORMAL))->isSuperTypeOf($mode)->or($argType->getIterableValueType()->isArray()->negate());
1010+
$isNormalCount = (new ConstantIntegerType(COUNT_NORMAL))->isSuperTypeOf($mode)->result->or($argType->getIterableValueType()->isArray()->negate());
10111011
}
10121012

10131013
if (

Diff for: src/Reflection/ParametersAcceptorSelector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ public static function selectFromTypes(
510510
if ($parameter->getType() instanceof MixedType) {
511511
$isSuperType = $isSuperType->and(TrinaryLogic::createMaybe());
512512
} else {
513-
$isSuperType = $isSuperType->and($parameter->getType()->isSuperTypeOf($type));
513+
$isSuperType = $isSuperType->and($parameter->getType()->isSuperTypeOf($type)->result);
514514
}
515515
}
516516

Diff for: src/Rules/Comparison/ImpossibleCheckTypeHelper.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public function findSpecifiedType(
282282
/** @var Type $resultType */
283283
$resultType = $sureType[1];
284284

285-
$results[] = $resultType->isSuperTypeOf($argumentType);
285+
$results[] = $resultType->isSuperTypeOf($argumentType)->result;
286286
}
287287

288288
foreach ($sureNotTypes as $sureNotType) {
@@ -300,7 +300,7 @@ public function findSpecifiedType(
300300
/** @var Type $resultType */
301301
$resultType = $sureNotType[1];
302302

303-
$results[] = $resultType->isSuperTypeOf($argumentType)->negate();
303+
$results[] = $resultType->isSuperTypeOf($argumentType)->negate()->result;
304304
}
305305

306306
if (count($results) === 0) {

Diff for: src/Rules/Methods/MethodSignatureRule.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function checkReturnTypeCompatibility(
219219
return [TrinaryLogic::createYes(), $returnType, $parentReturnType];
220220
}
221221

222-
return [$parentReturnType->isSuperTypeOf($returnType), TypehintHelper::decideType(
222+
return [$parentReturnType->isSuperTypeOf($returnType)->result, TypehintHelper::decideType(
223223
$currentVariant->getNativeReturnType(),
224224
$currentVariant->getPhpDocReturnType(),
225225
), $originalParentReturnType];
@@ -253,7 +253,7 @@ private function checkParameterTypeCompatibility(
253253
);
254254
$parentParameterType = $this->transformStaticType($declaringClass, $originalParameterType);
255255

256-
$parameterResults[] = [$parameterType->isSuperTypeOf($parentParameterType), TypehintHelper::decideType(
256+
$parameterResults[] = [$parameterType->isSuperTypeOf($parentParameterType)->result, TypehintHelper::decideType(
257257
$parameter->getNativeType(),
258258
$parameter->getPhpDocType(),
259259
), $originalParameterType];

Diff for: src/Type/Accessory/AccessoryArrayListType.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,23 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
8787
return new AcceptsResult($isArray->and($isList), []);
8888
}
8989

90-
public function isSuperTypeOf(Type $type): TrinaryLogic
91-
{
92-
return $this->isSuperTypeOfWithReason($type)->result;
93-
}
94-
95-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
90+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
9691
{
9792
if ($this->equals($type)) {
9893
return IsSuperTypeOfResult::createYes();
9994
}
10095

10196
if ($type instanceof CompoundType) {
102-
return $type->isSubTypeOfWithReason($this);
97+
return $type->isSubTypeOf($this);
10398
}
10499

105100
return new IsSuperTypeOfResult($type->isArray()->and($type->isList()), []);
106101
}
107102

108-
public function isSubTypeOf(Type $otherType): TrinaryLogic
109-
{
110-
return $this->isSubTypeOfWithReason($otherType)->result;
111-
}
112-
113-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
103+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
114104
{
115105
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
116-
return $otherType->isSuperTypeOfWithReason($this);
106+
return $otherType->isSuperTypeOf($this);
117107
}
118108

119109
return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isList()), []))
@@ -122,7 +112,7 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
122112

123113
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
124114
{
125-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
115+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
126116
}
127117

128118
public function equals(Type $type): bool
@@ -147,7 +137,7 @@ public function isOffsetAccessLegal(): TrinaryLogic
147137

148138
public function hasOffsetValueType(Type $offsetType): TrinaryLogic
149139
{
150-
return $this->getIterableKeyType()->isSuperTypeOf($offsetType)->and(TrinaryLogic::createMaybe());
140+
return $this->getIterableKeyType()->isSuperTypeOf($offsetType)->result->and(TrinaryLogic::createMaybe());
151141
}
152142

153143
public function getOffsetValueType(Type $offsetType): Type

Diff for: src/Type/Accessory/AccessoryLiteralStringType.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,10 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
8080
return new AcceptsResult($type->isLiteralString(), []);
8181
}
8282

83-
public function isSuperTypeOf(Type $type): TrinaryLogic
84-
{
85-
return $this->isSuperTypeOfWithReason($type)->result;
86-
}
87-
88-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
83+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
8984
{
9085
if ($type instanceof CompoundType) {
91-
return $type->isSubTypeOfWithReason($this);
86+
return $type->isSubTypeOf($this);
9287
}
9388

9489
if ($this->equals($type)) {
@@ -98,15 +93,10 @@ public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
9893
return new IsSuperTypeOfResult($type->isLiteralString(), []);
9994
}
10095

101-
public function isSubTypeOf(Type $otherType): TrinaryLogic
102-
{
103-
return $this->isSubTypeOfWithReason($otherType)->result;
104-
}
105-
106-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
96+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
10797
{
10898
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
109-
return $otherType->isSuperTypeOfWithReason($this);
99+
return $otherType->isSuperTypeOf($this);
110100
}
111101

112102
return (new IsSuperTypeOfResult($otherType->isLiteralString(), []))
@@ -115,7 +105,7 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
115105

116106
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
117107
{
118-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
108+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
119109
}
120110

121111
public function equals(Type $type): bool

Diff for: src/Type/Accessory/AccessoryLowercaseStringType.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,10 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
7676
return new AcceptsResult($type->isLowercaseString(), []);
7777
}
7878

79-
public function isSuperTypeOf(Type $type): TrinaryLogic
80-
{
81-
return $this->isSuperTypeOfWithReason($type)->result;
82-
}
83-
84-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
79+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
8580
{
8681
if ($type instanceof CompoundType) {
87-
return $type->isSubTypeOfWithReason($this);
82+
return $type->isSubTypeOf($this);
8883
}
8984

9085
if ($this->equals($type)) {
@@ -94,15 +89,10 @@ public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
9489
return new IsSuperTypeOfResult($type->isLowercaseString(), []);
9590
}
9691

97-
public function isSubTypeOf(Type $otherType): TrinaryLogic
98-
{
99-
return $this->isSubTypeOfWithReason($otherType)->result;
100-
}
101-
102-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
92+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
10393
{
10494
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
105-
return $otherType->isSuperTypeOfWithReason($this);
95+
return $otherType->isSuperTypeOf($this);
10696
}
10797

10898
return (new IsSuperTypeOfResult($otherType->isLowercaseString(), []))
@@ -111,7 +101,7 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
111101

112102
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
113103
{
114-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
104+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
115105
}
116106

117107
public function equals(Type $type): bool

Diff for: src/Type/Accessory/AccessoryNonEmptyStringType.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,10 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
7878
return new AcceptsResult($type->isNonEmptyString(), []);
7979
}
8080

81-
public function isSuperTypeOf(Type $type): TrinaryLogic
82-
{
83-
return $this->isSuperTypeOfWithReason($type)->result;
84-
}
85-
86-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
81+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
8782
{
8883
if ($type instanceof CompoundType) {
89-
return $type->isSubTypeOfWithReason($this);
84+
return $type->isSubTypeOf($this);
9085
}
9186

9287
if ($this->equals($type)) {
@@ -100,15 +95,10 @@ public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
10095
return new IsSuperTypeOfResult($type->isNonEmptyString(), []);
10196
}
10297

103-
public function isSubTypeOf(Type $otherType): TrinaryLogic
104-
{
105-
return $this->isSubTypeOfWithReason($otherType)->result;
106-
}
107-
108-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
98+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
10999
{
110100
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
111-
return $otherType->isSuperTypeOfWithReason($this);
101+
return $otherType->isSuperTypeOf($this);
112102
}
113103

114104
return (new IsSuperTypeOfResult($otherType->isNonEmptyString(), []))
@@ -117,7 +107,7 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
117107

118108
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
119109
{
120-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
110+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
121111
}
122112

123113
public function equals(Type $type): bool

Diff for: src/Type/Accessory/AccessoryNonFalsyStringType.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,10 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
7878
return new AcceptsResult($type->isNonFalsyString(), []);
7979
}
8080

81-
public function isSuperTypeOf(Type $type): TrinaryLogic
82-
{
83-
return $this->isSuperTypeOfWithReason($type)->result;
84-
}
85-
86-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
81+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
8782
{
8883
if ($type instanceof CompoundType) {
89-
return $type->isSubTypeOfWithReason($this);
84+
return $type->isSubTypeOf($this);
9085
}
9186

9287
if ($this->equals($type)) {
@@ -96,15 +91,10 @@ public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
9691
return new IsSuperTypeOfResult($type->isNonFalsyString(), []);
9792
}
9893

99-
public function isSubTypeOf(Type $otherType): TrinaryLogic
100-
{
101-
return $this->isSubTypeOfWithReason($otherType)->result;
102-
}
103-
104-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
94+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
10595
{
10696
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
107-
return $otherType->isSuperTypeOfWithReason($this);
97+
return $otherType->isSuperTypeOf($this);
10898
}
10999

110100
if ($otherType instanceof AccessoryNonEmptyStringType) {
@@ -117,7 +107,7 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
117107

118108
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
119109
{
120-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
110+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
121111
}
122112

123113
public function equals(Type $type): bool

Diff for: src/Type/Accessory/AccessoryNumericStringType.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,10 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
7777
return new AcceptsResult($type->isNumericString(), []);
7878
}
7979

80-
public function isSuperTypeOf(Type $type): TrinaryLogic
81-
{
82-
return $this->isSuperTypeOfWithReason($type)->result;
83-
}
84-
85-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
80+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
8681
{
8782
if ($type instanceof CompoundType) {
88-
return $type->isSubTypeOfWithReason($this);
83+
return $type->isSubTypeOf($this);
8984
}
9085

9186
if ($this->equals($type)) {
@@ -95,15 +90,10 @@ public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
9590
return new IsSuperTypeOfResult($type->isNumericString(), []);
9691
}
9792

98-
public function isSubTypeOf(Type $otherType): TrinaryLogic
99-
{
100-
return $this->isSubTypeOfWithReason($otherType)->result;
101-
}
102-
103-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
93+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
10494
{
10595
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
106-
return $otherType->isSuperTypeOfWithReason($this);
96+
return $otherType->isSuperTypeOf($this);
10797
}
10898

10999
return (new IsSuperTypeOfResult($otherType->isNumericString(), []))
@@ -120,7 +110,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsRes
120110
return AcceptsResult::createYes();
121111
}
122112

123-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
113+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
124114
}
125115

126116
public function equals(Type $type): bool

Diff for: src/Type/Accessory/HasMethodType.php

+4-14
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,15 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
7171
return AcceptsResult::createFromBoolean($this->equals($type));
7272
}
7373

74-
public function isSuperTypeOf(Type $type): TrinaryLogic
75-
{
76-
return $this->isSuperTypeOfWithReason($type)->result;
77-
}
78-
79-
public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
74+
public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
8075
{
8176
return new IsSuperTypeOfResult($type->hasMethod($this->methodName), []);
8277
}
8378

84-
public function isSubTypeOf(Type $otherType): TrinaryLogic
85-
{
86-
return $this->isSubTypeOfWithReason($otherType)->result;
87-
}
88-
89-
public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
79+
public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
9080
{
9181
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
92-
return $otherType->isSuperTypeOfWithReason($this);
82+
return $otherType->isSuperTypeOf($this);
9383
}
9484

9585
if ($this->isCallable()->yes() && $otherType->isCallable()->yes()) {
@@ -107,7 +97,7 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
10797

10898
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult
10999
{
110-
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
100+
return $this->isSubTypeOf($acceptingType)->toAcceptsResult();
111101
}
112102

113103
public function equals(Type $type): bool

0 commit comments

Comments
 (0)