-
Notifications
You must be signed in to change notification settings - Fork 504
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
RegexArrayShapeMatcher - when all groups are optional return a more… #3189
Conversation
This pull request has been marked as ready for review. |
quest for another PR: how to get smarter for alternations in the regex. maybe tomorrow ;) |
…recise union, instead of a shape with optional offsets
took me a lot of attempts but I think the current design works now. when a regex contains only a single optional capturing group, we build a more precise constant type. |
This pull request has been marked as ready for review. |
|
||
namespace PHPStan\Type\Php; | ||
|
||
class RegexNonCapturingGroup |
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.
the optional groups detection, now also takes non-capturing groups into account... these do not capture results itself, but might impact nested capturing groups
// if only one top level capturing optional group exists | ||
// we build a more precise constant union of a empty-match and a match with the group |
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.
I am limiting to this specific case for now, because whether $matches contains a offset or not depends on many factors. I did this already for more stuff, but it was easily breaking stuff.
will bring back more sophiscated stuff in future PRs
Thank you! |
…precise union, instead of a shape with optional offsets
implements the feature request https://phpstan.org/r/fac92fd0-b78e-4e36-9089-ec8f7ece17c6
refs phpstan/phpstan#11221 (comment)