Skip to content

Commit d5b0867

Browse files
committed
RegexArrayShapeMatcher - use ConstantArrayTypeBuilder
1 parent 69db4ae commit d5b0867

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Type/Php/RegexArrayShapeMatcher.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\TrinaryLogic;
99
use PHPStan\Type\Accessory\AccessoryArrayListType;
1010
use PHPStan\Type\ArrayType;
11-
use PHPStan\Type\Constant\ConstantArrayType;
1211
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
1312
use PHPStan\Type\Constant\ConstantIntegerType;
1413
use PHPStan\Type\Constant\ConstantStringType;
@@ -62,7 +61,7 @@ public function matchExpr(Expr $patternExpr, ?Type $flagsType, TrinaryLogic $was
6261
private function matchPatternType(Type $patternType, ?Type $flagsType, TrinaryLogic $wasMatched, bool $matchesAll): ?Type
6362
{
6463
if ($wasMatched->no()) {
65-
return new ConstantArrayType([], []);
64+
return ConstantArrayTypeBuilder::createEmpty()->getArray();
6665
}
6766

6867
$constantStrings = $patternType->getConstantStrings();
@@ -140,8 +139,11 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
140139

141140
if (!$this->containsUnmatchedAsNull($flags, $matchesAll)) {
142141
// 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+
143145
$combiType = TypeCombinator::union(
144-
new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($flags, $matchesAll)], [1], [], TrinaryLogic::createYes()),
146+
$builder->getArray(),
145147
$combiType,
146148
);
147149
}
@@ -199,7 +201,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
199201
)
200202
) {
201203
// 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();
203208
}
204209

205210
return TypeCombinator::union(...$combiTypes);
@@ -279,7 +284,7 @@ private function buildArrayType(
279284
$arrayType = TypeCombinator::intersect(new ArrayType(new IntegerType(), $builder->getArray()), new AccessoryArrayListType());
280285
if (!$wasMatched->yes()) {
281286
$arrayType = TypeCombinator::union(
282-
new ConstantArrayType([], []),
287+
ConstantArrayTypeBuilder::createEmpty()->getArray(),
283288
$arrayType,
284289
);
285290
}

0 commit comments

Comments
 (0)