Skip to content

Commit f0a9fd7

Browse files
committed
Pass TrinaryLogic into ConstantArrayType isList everywhere
1 parent a8818be commit f0a9fd7

16 files changed

+31
-26
lines changed

src/Type/Accessory/AccessoryLiteralStringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function toArray(): Type
188188
[$this],
189189
[1],
190190
[],
191-
true,
191+
TrinaryLogic::createYes(),
192192
);
193193
}
194194

src/Type/Accessory/AccessoryNonEmptyStringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function toArray(): Type
189189
[$this],
190190
[1],
191191
[],
192-
true,
192+
TrinaryLogic::createYes(),
193193
);
194194
}
195195

src/Type/Accessory/AccessoryNonFalsyStringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function toArray(): Type
189189
[$this],
190190
[1],
191191
[],
192-
true,
192+
TrinaryLogic::createYes(),
193193
);
194194
}
195195

src/Type/Accessory/AccessoryNumericStringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function toArray(): Type
191191
[$this],
192192
[1],
193193
[],
194-
true,
194+
TrinaryLogic::createYes(),
195195
);
196196
}
197197

src/Type/BooleanType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function toArray(): Type
8787
[$this],
8888
[1],
8989
[],
90-
true,
90+
TrinaryLogic::createYes(),
9191
);
9292
}
9393

src/Type/ClosureType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function toArray(): Type
340340
[$this],
341341
[1],
342342
[],
343-
true,
343+
TrinaryLogic::createYes(),
344344
);
345345
}
346346

src/Type/Constant/ConstantArrayType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ public function unsetOffset(Type $offsetType): Type
695695
$k++;
696696
}
697697

698-
return new self($newKeyTypes, $newValueTypes, $this->nextAutoIndexes, $newOptionalKeys, false);
698+
return new self($newKeyTypes, $newValueTypes, $this->nextAutoIndexes, $newOptionalKeys, TrinaryLogic::createNo());
699699
}
700700

701701
return $this;
@@ -724,7 +724,7 @@ public function unsetOffset(Type $offsetType): Type
724724
}
725725
}
726726

727-
return new self($this->keyTypes, $this->valueTypes, $this->nextAutoIndexes, $optionalKeys, false);
727+
return new self($this->keyTypes, $this->valueTypes, $this->nextAutoIndexes, $optionalKeys, TrinaryLogic::createNo());
728728
}
729729

730730
$optionalKeys = $this->optionalKeys;
@@ -734,7 +734,7 @@ public function unsetOffset(Type $offsetType): Type
734734
continue;
735735
}
736736
$optionalKeys[] = $i;
737-
$isList = false;
737+
$isList = TrinaryLogic::createNo();
738738
}
739739
$optionalKeys = array_values(array_unique($optionalKeys));
740740

src/Type/Constant/ConstantArrayTypeBuilder.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Type\Constant;
44

55
use PHPStan\ShouldNotHappenException;
6+
use PHPStan\TrinaryLogic;
67
use PHPStan\Type\Accessory\AccessoryArrayListType;
78
use PHPStan\Type\Accessory\NonEmptyArrayType;
89
use PHPStan\Type\Accessory\OversizedArrayType;
@@ -42,14 +43,14 @@ private function __construct(
4243
private array $valueTypes,
4344
private array $nextAutoIndexes,
4445
private array $optionalKeys,
45-
private bool $isList,
46+
private TrinaryLogic $isList,
4647
)
4748
{
4849
}
4950

5051
public static function createEmpty(): self
5152
{
52-
return new self([], [], [0], [], true);
53+
return new self([], [], [0], [], TrinaryLogic::createYes());
5354
}
5455

5556
public static function createFromConstantArray(ConstantArrayType $startArrayType): self
@@ -59,7 +60,7 @@ public static function createFromConstantArray(ConstantArrayType $startArrayType
5960
$startArrayType->getValueTypes(),
6061
$startArrayType->getNextAutoIndexes(),
6162
$startArrayType->getOptionalKeys(),
62-
$startArrayType->isList()->yes(),
63+
$startArrayType->isList(),
6364
);
6465

6566
if (count($startArrayType->getKeyTypes()) > self::ARRAY_COUNT_LIMIT) {
@@ -162,7 +163,7 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
162163
$min = min($this->nextAutoIndexes);
163164
$max = max($this->nextAutoIndexes);
164165
if ($offsetType->getValue() > $min) {
165-
$this->isList = false;
166+
$this->isList = TrinaryLogic::createNo();
166167
}
167168
if ($offsetType->getValue() >= $max) {
168169
/** @var int|float $newAutoIndex */
@@ -177,7 +178,7 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
177178
}
178179
}
179180
} else {
180-
$this->isList = false;
181+
$this->isList = TrinaryLogic::createNo();
181182
}
182183

183184
if ($optional) {
@@ -191,7 +192,7 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
191192
return;
192193
}
193194

194-
$this->isList = false;
195+
$this->isList = TrinaryLogic::createNo();
195196

196197
$scalarTypes = $offsetType->getConstantScalarTypes();
197198
if (count($scalarTypes) === 0) {
@@ -254,7 +255,7 @@ public function setOffsetValueType(?Type $offsetType, Type $valueType, bool $opt
254255
if ($offsetType === null) {
255256
$offsetType = TypeCombinator::union(...array_map(static fn (int $index) => new ConstantIntegerType($index), $this->nextAutoIndexes));
256257
} else {
257-
$this->isList = false;
258+
$this->isList = TrinaryLogic::createNo();
258259
}
259260

260261
$this->keyTypes[] = $offsetType;
@@ -297,7 +298,7 @@ public function getArray(): Type
297298
$array = TypeCombinator::intersect($array, new OversizedArrayType());
298299
}
299300

300-
if ($this->isList) {
301+
if ($this->isList->yes()) {
301302
$array = AccessoryArrayListType::intersectWith($array);
302303
}
303304

@@ -306,7 +307,7 @@ public function getArray(): Type
306307

307308
public function isList(): bool
308309
{
309-
return $this->isList;
310+
return $this->isList->yes();
310311
}
311312

312313
}

src/Type/FloatType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function toArray(): Type
135135
[$this],
136136
[1],
137137
[],
138-
true,
138+
TrinaryLogic::createYes(),
139139
);
140140
}
141141

src/Type/Generic/TemplateConstantArrayType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(
2121
ConstantArrayType $bound,
2222
)
2323
{
24-
parent::__construct($bound->getKeyTypes(), $bound->getValueTypes(), $bound->getNextAutoIndexes(), $bound->getOptionalKeys(), $bound->isList()->yes());
24+
parent::__construct($bound->getKeyTypes(), $bound->getValueTypes(), $bound->getNextAutoIndexes(), $bound->getOptionalKeys(), $bound->isList());
2525
$this->scope = $scope;
2626
$this->strategy = $templateTypeStrategy;
2727
$this->variance = $templateTypeVariance;

0 commit comments

Comments
 (0)