Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jun 25, 2024
1 parent da5a316 commit 37070ff
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Type/Php/RegexArrayShapeMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched
}

$overallType = $builder->getArray();
$constantArrays = $overallType->getConstantArrays();

// when all groups are optional return a more precise union, instead of a shape with optional offsets
if (
$countGroups === $trailingOptionals
&& $wasMatched->yes()
&& count($constantArrays) > 0
) {
$constantArrays = $overallType->getConstantArrays();
if ($constantArrays === []) {
return $overallType;
}

$result = [
// first item in matches contains the overall match.
new ConstantArrayType([new ConstantIntegerType(0)], [new StringType()]),
];

foreach ($constantArrays as $constantArray) {
// same shape, but without optional keys
$result[] = new ConstantArrayType(
Expand Down

0 comments on commit 37070ff

Please sign in to comment.