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

[Naming] Remove matchesStringName() check completely from NodeNameResolver, including endsWith() method - use getName() and compare directly instead #4954

Merged
merged 5 commits into from Sep 9, 2023

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Sep 9, 2023

Based on feedback from @staabm , I got an idea to remove the regexes from naming completely. This would make naming API intuitive and clean.

It's still possible to check any name against regex with $this->getName($node) if needed (not recommended though).


What do you think? :) cc @staabm @samsonasik


The single fixture would have to be adjusted, or skipped. Underscore rules were removed long time ago and type actually matches there.

@TomasVotruba TomasVotruba force-pushed the tv-naming-postfix-3 branch 2 times, most recently from bea1813 to 7ebaf11 Compare September 9, 2023 14:44
*/
public function endsWith(string $currentName, string $expectedName): bool
public function endsWith(Node $node, string|array $suffix): bool
Copy link
Contributor

@staabm staabm Sep 9, 2023

Choose a reason for hiding this comment

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

Do we need this method at all, or should just use the matchesName(.., 'myname*') instead?

A caller could even use getName() and invoke start_ or ends_with in its own.

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh I see. you want todo it the other way arround. drop all regex magic, in case thats good enough for all existing use-cases

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. Removing endsWith() and startsWith() might make more sense. There are only 5 cases in our whole code base, so I think it would be better choice.

Copy link
Member

Choose a reason for hiding this comment

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

startsWith() seems already used in rector-phpunit and rector-symfony so that should be changed first

rectorphp/rector-phpunit@f07d7f0

rectorphp/rector-symfony@b9303b5

@TomasVotruba TomasVotruba force-pushed the tv-naming-postfix-3 branch 3 times, most recently from 7f2c806 to 6a88d44 Compare September 9, 2023 17:06
@TomasVotruba
Copy link
Member Author

Ready for 2nd round of reviews 🙂

@@ -201,27 +201,27 @@ private function isInLoopWithoutContinueOrBreak(If_ $if): bool
private function processReplaceIfs(
If_ $if,
array $conditions,
Return_ $ifNextReturnClone,
Return_ $cloneIffNextReturn,
Copy link
Contributor

Choose a reason for hiding this comment

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

are these class renaming changes related to the actual goal of this PR?

if not, separating these would help to focus on whats important

Copy link
Member Author

Choose a reason for hiding this comment

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

They're result of fixed naming check 👍 The endsWith() was buggy.

@TomasVotruba TomasVotruba force-pushed the tv-naming-postfix-3 branch 2 times, most recently from 8ff0d38 to 48ed8a7 Compare September 9, 2023 22:38
@TomasVotruba TomasVotruba changed the title [Naming] Remove regex check completely from NodeNameResolver [Naming] Remove regex check completely from NodeNameResolver, including endsWith() method - use getName() and compare directly instead Sep 9, 2023
@TomasVotruba TomasVotruba changed the title [Naming] Remove regex check completely from NodeNameResolver, including endsWith() method - use getName() and compare directly instead [Naming] Remove matchesStringName() check completely from NodeNameResolver, including endsWith() method - use getName() and compare directly instead Sep 9, 2023
@TomasVotruba TomasVotruba force-pushed the tv-naming-postfix-3 branch 2 times, most recently from b719538 to 9ec7c18 Compare September 9, 2023 22:43
@TomasVotruba TomasVotruba enabled auto-merge (squash) September 9, 2023 22:45
@TomasVotruba TomasVotruba merged commit c97e4ff into main Sep 9, 2023
40 checks passed
@TomasVotruba TomasVotruba deleted the tv-naming-postfix-3 branch September 9, 2023 22:47
@TomasVotruba
Copy link
Member Author

Let's ship it 👍

@samsonasik
Copy link
Member

@TomasVotruba @staabm it seems cause error on $this->isName($node->name, 'assert*') usage on rector-phpunit when rules-tests registered to phpunit.xml, it was never executed, see

rectorphp/rector-phpunit#251 (review)

https://github.com/rectorphp/rector-phpunit/blob/2800f5c374cffc20cbdfb221ce033b46a3a8003d/rules/CodeQuality/Rector/Class_/PreferPHPUnitThisCallRector.php#L97-L99

@samsonasik
Copy link
Member

@TomasVotruba @staabm also, documentation need to be updated as it no longer works:

$this->isName($node->name, 'set*')

https://github.com/rectorphp/getrector-com/blob/eb645522359c6fed4dccc98556dab0d21658fad3/resources/docs/custom-rule.md?plain=1#L45

@samsonasik
Copy link
Member

@samsonasik
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants