Skip to content
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 - Narrow types in alternation of top level capturing groups #3202

Merged
merged 5 commits into from
Jul 1, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 1, 2024

fixes the 2 repros of phpstan/phpstan#11221 (comment)

@staabm staabm marked this pull request as ready for review July 1, 2024 13:09
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@staabm staabm force-pushed the regex-opt-shapes branch from 8ce1551 to 6a93084 Compare July 1, 2024 13:13
private bool $inOptionalQuantification,
private RegexCapturingGroup|RegexNonCapturingGroup|null $parent,
)
{
$this->id = self::$idGenerator;
self::$idGenerator++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like global state like that. This should be passed as a plain number from the outside and counted in the instance that creates objects of this class.

}
assertType('array{0: string, 1: string, 2: string, 3?: string, 4?: string}', $matches);

if (preg_match('~^(?:(\\d+)x(\\d+)|(\\d+)|x(\\d+))?$~', $size, $matches) !== 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to divide this in multiple functions, reusing the $matches variable like that seems dirty to me.

@staabm staabm force-pushed the regex-opt-shapes branch from 2757c15 to 1ad0179 Compare July 1, 2024 14:17
@staabm
Copy link
Contributor Author

staabm commented Jul 1, 2024

feedback addressed - thank you

@ondrejmirtes ondrejmirtes merged commit 579402b into phpstan:1.11.x Jul 1, 2024
251 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the regex-opt-shapes branch July 1, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants