Skip to content

Commit e75996b

Browse files
committed
[BCB] Parameter $isList in ConstantArrayType constructor can only be TrinaryLogic
1 parent 45b4a85 commit e75996b

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

Diff for: UPGRADING.md

+1
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,4 @@ Instead of `PHPStanTestCase::createBroker()`, call `PHPStanTestCase::createRefle
273273
* Remove `TypeUtils::getEnumCaseObjects()`, use [`Type::getEnumCases()`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.Type.html#_getEnumCases) instead
274274
* Remove `TypeUtils::containsCallable()`, use [`Type::isCallable()`](https://apiref.phpstan.org/2.0.x/PHPStan.Type.Type.html#_isCallable) instead
275275
* Removed `Scope::doNotTreatPhpDocTypesAsCertain()`, use `getNativeType()` instead
276+
* Parameter `$isList` in `ConstantArrayType` constructor can only be `TrinaryLogic`, no longer bool

Diff for: src/Type/Constant/ConstantArrayType.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
use function count;
6060
use function implode;
6161
use function in_array;
62-
use function is_bool;
6362
use function is_int;
6463
use function is_string;
6564
use function min;
@@ -108,7 +107,7 @@ public function __construct(
108107
private array $valueTypes,
109108
int|array $nextAutoIndexes = [0],
110109
private array $optionalKeys = [],
111-
bool|TrinaryLogic $isList = false,
110+
?TrinaryLogic $isList = null,
112111
)
113112
{
114113
assert(count($keyTypes) === count($valueTypes));
@@ -124,8 +123,8 @@ public function __construct(
124123
$isList = TrinaryLogic::createYes();
125124
}
126125

127-
if (is_bool($isList)) {
128-
$isList = TrinaryLogic::createFromBoolean($isList);
126+
if ($isList === null) {
127+
$isList = TrinaryLogic::createNo();
129128
}
130129
$this->isList = $isList;
131130
}

Diff for: src/Type/Php/RegexArrayShapeMatcher.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
149149
if (!$this->containsUnmatchedAsNull($flags, $matchesAll)) {
150150
// positive match has a subject but not any capturing group
151151
$combiType = TypeCombinator::union(
152-
new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], true),
152+
new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], TrinaryLogic::createYes()),
153153
$combiType,
154154
);
155155
}
@@ -214,7 +214,7 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
214214
)
215215
) {
216216
// positive match has a subject but not any capturing group
217-
$combiTypes[] = new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], true);
217+
$combiTypes[] = new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], TrinaryLogic::createYes());
218218
}
219219

220220
return TypeCombinator::union(...$combiTypes);

Diff for: tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -886,14 +886,14 @@ public function dataValuesArray(): iterable
886886
], [
887887
new ConstantStringType('a'),
888888
new ConstantStringType('b'),
889-
], [20], [], false),
889+
], [20], [], TrinaryLogic::createNo()),
890890
new ConstantArrayType([
891891
new ConstantIntegerType(0),
892892
new ConstantIntegerType(1),
893893
], [
894894
new ConstantStringType('a'),
895895
new ConstantStringType('b'),
896-
], [2], [], true),
896+
], [2], [], TrinaryLogic::createYes()),
897897
];
898898

899899
yield 'optional-1' => [
@@ -909,7 +909,7 @@ public function dataValuesArray(): iterable
909909
new ConstantStringType('c'),
910910
new ConstantStringType('d'),
911911
new ConstantStringType('e'),
912-
], [15], [1, 3], false),
912+
], [15], [1, 3], TrinaryLogic::createNo()),
913913
new ConstantArrayType([
914914
new ConstantIntegerType(0),
915915
new ConstantIntegerType(1),
@@ -922,7 +922,7 @@ public function dataValuesArray(): iterable
922922
new UnionType([new ConstantStringType('c'), new ConstantStringType('d'), new ConstantStringType('e')]),
923923
new UnionType([new ConstantStringType('d'), new ConstantStringType('e')]),
924924
new ConstantStringType('e'),
925-
], [3, 4, 5], [3, 4], true),
925+
], [3, 4, 5], [3, 4], TrinaryLogic::createYes()),
926926
];
927927

928928
yield 'optional-2' => [
@@ -938,7 +938,7 @@ public function dataValuesArray(): iterable
938938
new ConstantStringType('c'),
939939
new ConstantStringType('d'),
940940
new ConstantStringType('e'),
941-
], [15], [0, 2, 4], false),
941+
], [15], [0, 2, 4], TrinaryLogic::createNo()),
942942
new ConstantArrayType([
943943
new ConstantIntegerType(0),
944944
new ConstantIntegerType(1),
@@ -951,7 +951,7 @@ public function dataValuesArray(): iterable
951951
new UnionType([new ConstantStringType('c'), new ConstantStringType('d'), new ConstantStringType('e')]),
952952
new UnionType([new ConstantStringType('d'), new ConstantStringType('e')]),
953953
new ConstantStringType('e'),
954-
], [2, 3, 4, 5], [2, 3, 4], true),
954+
], [2, 3, 4, 5], [2, 3, 4], TrinaryLogic::createYes()),
955955
];
956956

957957
yield 'optional-at-end-and-list' => [
@@ -963,7 +963,7 @@ public function dataValuesArray(): iterable
963963
new ConstantStringType('a'),
964964
new ConstantStringType('b'),
965965
new ConstantStringType('c'),
966-
], [11, 12, 13], [1, 2], true),
966+
], [11, 12, 13], [1, 2], TrinaryLogic::createYes()),
967967
new ConstantArrayType([
968968
new ConstantIntegerType(0),
969969
new ConstantIntegerType(1),
@@ -972,7 +972,7 @@ public function dataValuesArray(): iterable
972972
new ConstantStringType('a'),
973973
new ConstantStringType('b'),
974974
new ConstantStringType('c'),
975-
], [1, 2, 3], [1, 2], true),
975+
], [1, 2, 3], [1, 2], TrinaryLogic::createYes()),
976976
];
977977

978978
yield 'optional-at-end-but-not-list' => [
@@ -984,7 +984,7 @@ public function dataValuesArray(): iterable
984984
new ConstantStringType('a'),
985985
new ConstantStringType('b'),
986986
new ConstantStringType('c'),
987-
], [11, 12, 13], [1, 2], false),
987+
], [11, 12, 13], [1, 2], TrinaryLogic::createNo()),
988988
new ConstantArrayType([
989989
new ConstantIntegerType(0),
990990
new ConstantIntegerType(1),
@@ -993,7 +993,7 @@ public function dataValuesArray(): iterable
993993
new ConstantStringType('a'),
994994
new UnionType([new ConstantStringType('b'), new ConstantStringType('c')]),
995995
new ConstantStringType('c'),
996-
], [1, 2, 3], [1, 2], true),
996+
], [1, 2, 3], [1, 2], TrinaryLogic::createYes()),
997997
];
998998
}
999999

Diff for: tests/PHPStan/Type/TypeGetFiniteTypesTest.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Type;
44

55
use PHPStan\Testing\PHPStanTestCase;
6+
use PHPStan\TrinaryLogic;
67
use PHPStan\Type\Constant\ConstantArrayType;
78
use PHPStan\Type\Constant\ConstantBooleanType;
89
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -96,28 +97,28 @@ public function dataGetFiniteTypes(): iterable
9697
], [
9798
new ConstantBooleanType(true),
9899
new ConstantBooleanType(true),
99-
], 2, [], true),
100+
], 2, [], TrinaryLogic::createYes()),
100101
new ConstantArrayType([
101102
new ConstantIntegerType(0),
102103
new ConstantIntegerType(1),
103104
], [
104105
new ConstantBooleanType(true),
105106
new ConstantBooleanType(false),
106-
], 2, [], true),
107+
], 2, [], TrinaryLogic::createYes()),
107108
new ConstantArrayType([
108109
new ConstantIntegerType(0),
109110
new ConstantIntegerType(1),
110111
], [
111112
new ConstantBooleanType(false),
112113
new ConstantBooleanType(true),
113-
], 2, [], true),
114+
], 2, [], TrinaryLogic::createYes()),
114115
new ConstantArrayType([
115116
new ConstantIntegerType(0),
116117
new ConstantIntegerType(1),
117118
], [
118119
new ConstantBooleanType(false),
119120
new ConstantBooleanType(false),
120-
], 2, [], true),
121+
], 2, [], TrinaryLogic::createYes()),
121122
],
122123
];
123124
}

0 commit comments

Comments
 (0)