Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 don't like the SimplifyRegexPatternRector rule. Because it may change the behavior.
In PHP,
[0-9]and\d(also[a-zA-Z]and\w) are not exactly the same when usinguoption.https://3v4l.org/N8sQ5
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.
Ok, it seems due to called on
$rectorConfig->rule(), I removed it and revert its change on tests files 48f36efThere 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.
btw, the
uusage already skipped on rector :) https://getrector.com/demo/00372e82-e4bc-451b-a7a2-495637f29d88There 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.
Thanks!
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.
@kenjis do you want to re-enable
SimplifyRegexPatternRector? as it already skipped onuusage, see https://getrector.com/demo/00372e82-e4bc-451b-a7a2-495637f29d88There 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 don't want. Because these patterns have a bit different meanings.
An answer by ChatGPT:
In PHP's PCRE,
\dand[0-9]both match digits but are not exactly the same.Meaning:
\dmatches any digit character, including Unicode digits in some cases.[0-9]matches only ASCII digits (0-9).Compatibility:
\dcan match non-ASCII digits if Unicode is enabled.[0-9]always matches ASCII digits only.Performance:
[0-9]can be slightly faster since it's a simple character class.Example
Conclusion
Use
[0-9]for consistent matching of ASCII digits. Use\dif you need to match broader digit sets, considering encoding and Unicode support.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.
By the way, where does this code https://github.com/rectorphp/rector/blob/main/rules/CodeQuality/Rector/FuncCall/SimplifyRegexPatternRector.php check for the
uoption?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.
It only check delimiter, which limited to
~,#,/viaRegexPatternDetector, souin the last will always be skipped.