Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 34bf19a

Browse files
committedMar 24, 2025
RegexArrayShapeMatcher - use ConstantArrayTypeBuilder
1 parent f2f2ddf commit 34bf19a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed
 

‎src/Type/Php/RegexArrayShapeMatcher.php

+10-5
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();
@@ -146,8 +145,11 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
146145

147146
if (!$this->containsUnmatchedAsNull($flags, $matchesAll)) {
148147
// 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+
149151
$combiType = TypeCombinator::union(
150-
new ConstantArrayType([new ConstantIntegerType(0)], [$this->createSubjectValueType($subjectBaseType, $flags, $matchesAll)], [1], [], TrinaryLogic::createYes()),
152+
$builder->getArray(),
151153
$combiType,
152154
);
153155
}
@@ -206,7 +208,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
206208
)
207209
) {
208210
// 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();
210215
}
211216

212217
return TypeCombinator::union(...$combiTypes);
@@ -288,7 +293,7 @@ private function buildArrayType(
288293
$arrayType = TypeCombinator::intersect(new ArrayType(new IntegerType(), $builder->getArray()), new AccessoryArrayListType());
289294
if (!$wasMatched->yes()) {
290295
$arrayType = TypeCombinator::union(
291-
new ConstantArrayType([], []),
296+
ConstantArrayTypeBuilder::createEmpty()->getArray(),
292297
$arrayType,
293298
);
294299
}

0 commit comments

Comments
 (0)
Please sign in to comment.