|
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();
|
@@ -146,8 +145,11 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
|
146 | 145 |
|
147 | 146 | if (!$this->containsUnmatchedAsNull($flags, $matchesAll)) {
|
148 | 147 | // positive match has a subject but not any capturing group
|
| 148 | + $builder = ConstantArrayTypeBuilder::createEmpty(); |
| 149 | + $builder->setOffsetValueType(new ConstantIntegerType(0), $this->createSubjectValueType($subjectBaseType, $flags, $matchesAll)); |
| 150 | + |
149 | 151 | $combiType = TypeCombinator::union(
|
150 |
| - new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($subjectBaseType, $flags, $matchesAll)], [1], [], TrinaryLogic::createYes()), |
| 152 | + $builder->getArray(), |
151 | 153 | $combiType,
|
152 | 154 | );
|
153 | 155 | }
|
@@ -206,7 +208,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
|
206 | 208 | )
|
207 | 209 | ) {
|
208 | 210 | // positive match has a subject but not any capturing group
|
209 |
| - $combiTypes[] = new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($subjectBaseType, $flags, $matchesAll)], [1], [], TrinaryLogic::createYes()); |
| 211 | + $builder = ConstantArrayTypeBuilder::createEmpty(); |
| 212 | + $builder->setOffsetValueType(new ConstantIntegerType(0), $this->createSubjectValueType($subjectBaseType, $flags, $matchesAll)); |
| 213 | + |
| 214 | + $combiTypes[] = $builder->getArray(); |
210 | 215 | }
|
211 | 216 |
|
212 | 217 | return TypeCombinator::union(...$combiTypes);
|
@@ -288,7 +293,7 @@ private function buildArrayType(
|
288 | 293 | $arrayType = TypeCombinator::intersect(new ArrayType(new IntegerType(), $builder->getArray()), new AccessoryArrayListType());
|
289 | 294 | if (!$wasMatched->yes()) {
|
290 | 295 | $arrayType = TypeCombinator::union(
|
291 |
| - new ConstantArrayType([], []), |
| 296 | + ConstantArrayTypeBuilder::createEmpty()->getArray(), |
292 | 297 | $arrayType,
|
293 | 298 | );
|
294 | 299 | }
|
|
0 commit comments