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;

src/Type/IntegerType.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/Php/HrtimeFunctionReturnTypeExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr\FuncCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\FunctionReflection;
8+
use PHPStan\TrinaryLogic;
89
use PHPStan\Type\Constant\ConstantArrayType;
910
use PHPStan\Type\Constant\ConstantBooleanType;
1011
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -26,7 +27,7 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
2627

2728
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
2829
{
29-
$arrayType = new ConstantArrayType([new ConstantIntegerType(0), new ConstantIntegerType(1)], [new IntegerType(), new IntegerType()], [2]);
30+
$arrayType = new ConstantArrayType([new ConstantIntegerType(0), new ConstantIntegerType(1)], [new IntegerType(), new IntegerType()], [2], [], TrinaryLogic::createYes());
3031
$numberType = TypeUtils::toBenevolentUnion(TypeCombinator::union(new IntegerType(), new FloatType()));
3132

3233
if (count($functionCall->getArgs()) < 1) {

src/Type/Php/PregSplitDynamicReturnTypeExtension.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\FunctionReflection;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
9+
use PHPStan\TrinaryLogic;
910
use PHPStan\Type\Accessory\AccessoryArrayListType;
1011
use PHPStan\Type\ArrayType;
1112
use PHPStan\Type\BitwiseFlagHelper;
@@ -41,7 +42,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
4142
if ($flagsArg !== null && $this->bitwiseFlagAnalyser->bitwiseOrContainsConstant($flagsArg->value, $scope, 'PREG_SPLIT_OFFSET_CAPTURE')->yes()) {
4243
$type = new ArrayType(
4344
new IntegerType(),
44-
new ConstantArrayType([new ConstantIntegerType(0), new ConstantIntegerType(1)], [new StringType(), IntegerRangeType::fromInterval(0, null)], [2]),
45+
new ConstantArrayType([new ConstantIntegerType(0), new ConstantIntegerType(1)], [new StringType(), IntegerRangeType::fromInterval(0, null)], [2], [], TrinaryLogic::createYes()),
4546
);
4647
return TypeCombinator::union(AccessoryArrayListType::intersectWith($type), new ConstantBooleanType(false));
4748
}

src/Type/Php/StrSplitFunctionReturnTypeExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Reflection\FunctionReflection;
99
use PHPStan\Reflection\ParametersAcceptorSelector;
1010
use PHPStan\ShouldNotHappenException;
11+
use PHPStan\TrinaryLogic;
1112
use PHPStan\Type\Accessory\AccessoryArrayListType;
1213
use PHPStan\Type\Accessory\NonEmptyArrayType;
1314
use PHPStan\Type\ArrayType;
@@ -20,6 +21,7 @@
2021
use PHPStan\Type\StringType;
2122
use PHPStan\Type\Type;
2223
use PHPStan\Type\TypeCombinator;
24+
use function array_is_list;
2325
use function array_map;
2426
use function array_unique;
2527
use function count;
@@ -134,7 +136,7 @@ private static function createConstantArrayFrom(array $constantArray, Scope $sco
134136
$i++;
135137
}
136138

137-
return new ConstantArrayType($keyTypes, $valueTypes, $isList ? [$i] : [0]);
139+
return new ConstantArrayType($keyTypes, $valueTypes, $isList ? [$i] : [0], [], TrinaryLogic::createFromBoolean(array_is_list($constantArray)));
138140
}
139141

140142
}

src/Type/ResourceType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function toArray(): Type
7777
[$this],
7878
[1],
7979
[],
80-
true,
80+
TrinaryLogic::createYes(),
8181
);
8282
}
8383

src/Type/StringType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function toArray(): Type
155155
[$this],
156156
[1],
157157
[],
158-
true,
158+
TrinaryLogic::createYes(),
159159
);
160160
}
161161

0 commit comments

Comments
 (0)