-
Notifications
You must be signed in to change notification settings - Fork 506
RegexArrayShapeMatcher - turn more details immutable #3892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
$trailingOptionals = 0; | ||
foreach (array_reverse($groupList) as $captureGroup) { | ||
if (!$captureGroup->isOptional()) { | ||
break; | ||
} | ||
$trailingOptionals++; | ||
} | ||
|
||
$onlyOptionalTopLevelGroup = $this->getOnlyOptionalTopLevelGroup($groupList); | ||
$onlyTopLevelAlternation = $this->getOnlyTopLevelAlternation($groupList); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move operations previously did on array<int, RegexCapturingGroup> $captureGroups
into a dedicated class
@@ -154,12 +146,10 @@ private function matchRegex(string $regex, ?int $flags, TrinaryLogic $wasMatched | |||
); | |||
} | |||
|
|||
$onlyOptionalTopLevelGroup->clearOverrides(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more state clearing/handling
foreach ($groupCombo as $groupId) { | ||
$group = $comboList[$groupId]; | ||
$group->clearOverrides(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more state clearing/handling
This pull request has been marked as ready for review. |
Awesome, thank you!" |
goal: more immutability so we can in the end re-use hoa/ast parse results instead of regex lexing/parsing the same regex over and over (which shows up in perf profiles).
this also paves the way for phpstan/phpstan#12749 for which we need the group list to infer a more precise subject-type result