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

[NodeNameResolver] Check regex start delimiter and contains * on NodeNameResolver to use fnmatch() #4964

Merged
merged 5 commits into from
Sep 10, 2023

Conversation

samsonasik
Copy link
Member

@samsonasik samsonasik commented Sep 10, 2023

@TomasVotruba @staabm this is to avoid bc break with check string contains first :)

{
public function run()
{
return 'Nette\Utils\FileSystem';
Copy link
Member Author

Choose a reason for hiding this comment

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

the configured test is using Nette\*, this is new fixture to test it :)

->ruleWithConfiguration(StringClassNameToClassConstantRector::class, ['Nette\*', 'Error', 'Exception']);

Comment on lines -183 to -185
if (fnmatch($classToSkip, $classLikeName, FNM_NOESCAPE)) {
return true;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

here removed and ensure the new fixture working (skipped) as expected.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@samsonasik
Copy link
Member Author

samsonasik commented Sep 10, 2023

@TomasVotruba @staabm the check regex and fnmatch is still fast enough imo, since it check string start with regex delimiter, or contains * before executing regex.

@samsonasik samsonasik changed the title [NodeNameResolver] Check contains * on NodeNameResolver to use fnmatch() [NodeNameResolver] Check regex start delimiter and contains * on NodeNameResolver to use fnmatch() Sep 10, 2023
@@ -7,5 +7,10 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, ['Nette\*', 'Error', 'Exception']);
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
'Nette\*',
Copy link
Member Author

Choose a reason for hiding this comment

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

this is existing example using fnmatch().

->ruleWithConfiguration(StringClassNameToClassConstantRector::class, ['Nette\*', 'Error', 'Exception']);
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
'Nette\*',
'#^PHPStan\\\\Type#',
Copy link
Member Author

Choose a reason for hiding this comment

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

this is example using regex check.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I think it is ready.

@samsonasik
Copy link
Member Author

@TomasVotruba @staabm I am going to merge this :)

The reason it needs to be kept is this doesn't necessary make downgrade the performance, it still fast, since before check regex, it checked via native string php function first.

I will lookup other area for removing regex check instead of introducting BC break for current API :)

@samsonasik samsonasik merged commit ef6c8bc into main Sep 10, 2023
40 checks passed
@samsonasik samsonasik deleted the add-fnmatch branch September 10, 2023 12:58
@staabm
Copy link
Contributor

staabm commented Sep 10, 2023

I don't say we need to drop any regex stuff.. we should only use it when necessary. I worked only on the areas which hit performance.

its fine most of the time

@samsonasik
Copy link
Member Author

@staabm yes, that checked on last resort, also verified first before check regex, so it still fast, and we still have stable API.

@TomasVotruba
Copy link
Member

@samsonasik The BC break is ok here, as we've adjusted the used places. The goal to make isStringName() API less magical and use regex only when needed. Please revert to previous state.

samsonasik added a commit that referenced this pull request Sep 10, 2023
… on NodeNameResolver to use fnmatch() (#4964)"

This reverts commit ef6c8bc.
@samsonasik
Copy link
Member Author

@TomasVotruba ok, fine, I created PR

for it.

samsonasik added a commit that referenced this pull request Sep 10, 2023
* Revert "Fix fixture typo (#4967)"

This reverts commit 76cf20f.

* Revert "[NodeNameResolver] Check regex start delimiter and contains * on NodeNameResolver to use fnmatch() (#4964)"

This reverts commit ef6c8bc.

* fixture

* fixture

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <[email protected]>
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