|
8 | 8 | use PHPStan\TrinaryLogic; |
9 | 9 | use PHPStan\Type\Accessory\AccessoryArrayListType; |
10 | 10 | use PHPStan\Type\ArrayType; |
11 | | -use PHPStan\Type\Constant\ConstantArrayType; |
12 | 11 | use PHPStan\Type\Constant\ConstantArrayTypeBuilder; |
13 | 12 | use PHPStan\Type\Constant\ConstantIntegerType; |
14 | 13 | use PHPStan\Type\Constant\ConstantStringType; |
@@ -62,7 +61,7 @@ public function matchExpr(Expr $patternExpr, ?Type $flagsType, TrinaryLogic $was |
62 | 61 | private function matchPatternType(Type $patternType, ?Type $flagsType, TrinaryLogic $wasMatched, bool $matchesAll): ?Type |
63 | 62 | { |
64 | 63 | if ($wasMatched->no()) { |
65 | | - return new ConstantArrayType([], []); |
| 64 | + return ConstantArrayTypeBuilder::createEmpty()->getArray(); |
66 | 65 | } |
67 | 66 |
|
68 | 67 | $constantStrings = $patternType->getConstantStrings(); |
@@ -140,8 +139,11 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched |
140 | 139 |
|
141 | 140 | if (!$this->containsUnmatchedAsNull($flags, $matchesAll)) { |
142 | 141 | // positive match has a subject but not any capturing group |
| 142 | + $builder = ConstantArrayTypeBuilder::createEmpty(); |
| 143 | + $builder->setOffsetValueType(new ConstantIntegerType(0), $this->createSubjectValueType($flags, $matchesAll)); |
| 144 | + |
143 | 145 | $combiType = TypeCombinator::union( |
144 | | - new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], TrinaryLogic::createYes()), |
| 146 | + $builder->getArray(), |
145 | 147 | $combiType, |
146 | 148 | ); |
147 | 149 | } |
@@ -199,7 +201,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched |
199 | 201 | ) |
200 | 202 | ) { |
201 | 203 | // positive match has a subject but not any capturing group |
202 | | - $combiTypes[] = new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], TrinaryLogic::createYes()); |
| 204 | + $builder = ConstantArrayTypeBuilder::createEmpty(); |
| 205 | + $builder->setOffsetValueType(new ConstantIntegerType(0), $this->createSubjectValueType($flags, $matchesAll)); |
| 206 | + |
| 207 | + $combiTypes[] = $builder->getArray(); |
203 | 208 | } |
204 | 209 |
|
205 | 210 | return TypeCombinator::union(...$combiTypes); |
@@ -279,7 +284,7 @@ private function buildArrayType( |
279 | 284 | $arrayType = TypeCombinator::intersect(new ArrayType(new IntegerType(), $builder->getArray()), new AccessoryArrayListType()); |
280 | 285 | if (!$wasMatched->yes()) { |
281 | 286 | $arrayType = TypeCombinator::union( |
282 | | - new ConstantArrayType([], []), |
| 287 | + ConstantArrayTypeBuilder::createEmpty()->getArray(), |
283 | 288 | $arrayType, |
284 | 289 | ); |
285 | 290 | } |
|
0 commit comments