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

Keep numeric-strings in str_repeat() #2914

Merged
merged 10 commits into from
May 30, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Feb 13, 2024

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

This pull request has been marked as ready for review.

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Please put AccessoryNumericStringType in ConstantStringType::generalize() too.

@@ -74,6 +75,10 @@ public function getTypeFromFunctionCall(
$accessoryTypes[] = new AccessoryLiteralStringType();
}

if ($inputType->isNumericString()->yes()) {
$accessoryTypes[] = new AccessoryNumericStringType();
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid this can be a bit tricky. Repeating a numeric type multiple times can lead to a non-numeric type: https://3v4l.org/aRBdZ

Copy link
Member

Choose a reason for hiding this comment

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

So we should probably do it only with a constant (literal) types with no decimal points.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. fixed, thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should only be done for strings that only contain digits. Because of these numeric strings: https://3v4l.org/U4bM2

It should also be ensured that the multiplier is not 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ohh my, its even different across php versions ;)

https://3v4l.org/m6et3

@staabm staabm force-pushed the repeat-numeric-s branch 2 times, most recently from 6275102 to 480b972 Compare February 25, 2024 08:02
@staabm staabm marked this pull request as draft March 18, 2024 15:33
@staabm staabm force-pushed the repeat-numeric-s branch 3 times, most recently from 3851f2f to 0099b70 Compare April 6, 2024 17:04
@staabm
Copy link
Contributor Author

staabm commented Apr 7, 2024

I had a look into blackfire profiles and did not see any bottlenecks/resource hogs

@staabm staabm marked this pull request as ready for review April 8, 2024 08:28
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes changed the base branch from 1.10.x to 1.11.x May 30, 2024 13:59
@ondrejmirtes ondrejmirtes merged commit e099481 into phpstan:1.11.x May 30, 2024
442 of 443 checks passed
@ondrejmirtes
Copy link
Member

Thank you.

@staabm staabm deleted the repeat-numeric-s branch May 30, 2024 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants