-
-
Notifications
You must be signed in to change notification settings - Fork 741
update rule to support multiple occurrences of the class in the string #3648
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
Merged
TomasVotruba
merged 2 commits into
rectorphp:master
from
dobryy:replace-multiple-class-occurrences-in-string-rule
Jul 4, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...lassKeywordForClassNameResolutionRector/Fixture/mutiple_occurrences_in_one_string.php.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Rector\CodingStyle\Tests\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture; | ||
|
|
||
| class MultipleOccurrencesClass | ||
| { | ||
| public function run() | ||
| { | ||
| return 'Rector\CodingStyle\Tests\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture\MultipleOccurrencesClass::staticCall() && Rector\CodingStyle\Tests\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture\MultipleOccurrencesClass::staticCall()'; | ||
| } | ||
| } | ||
|
|
||
| ?> | ||
| ----- | ||
| <?php | ||
|
|
||
| namespace Rector\CodingStyle\Tests\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture; | ||
|
|
||
| class MultipleOccurrencesClass | ||
| { | ||
| public function run() | ||
| { | ||
| return \Rector\CodingStyle\Tests\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture\MultipleOccurrencesClass::class . '::staticCall() && ' . \Rector\CodingStyle\Tests\Rector\String_\UseClassKeywordForClassNameResolutionRector\Fixture\MultipleOccurrencesClass::class . '::staticCall()'; | ||
| } | ||
| } | ||
|
|
||
| ?> |
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.
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.
This looks very crazy 😄 What is going on here?
It's some node stacking in a loop?
Better collect concat nodes in an array, e.g. to $contacts
And resolve later in in go, e.g.
It's much easier to debug and test in case of troubles.
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.
This solution helped me to keep myself away from becoming crazy :D Believe me or not but is a million percents better than a couple of the solution I had before this one :D
Maybe it is not clear but this solution is able to process the random amount of class name occurrences in the string (not only one or two) that is why concatenation in the loop is required.
When it comes to the condition it helps to avoid the first empty Node. If I won't use it I'll have to create the first Node with an empty value outside of the loop for first concatenation which will then produce empty node which will in final result look like
While it is not a problem to create the array of nodes with the current solution... I can't imagine what I should implement under
...in your code to cover the cases in the test fixtures.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 see, I think what you mean. Nodes can break human brain sometimes, I've been there :D.
Don't worry about it 👍 , I'll check if there are is some space after we merge this.
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.
Not sure how much you care about perfomance but to make this loop a bit nicer I can also
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.
Unless a memory/performance leak, it's not an issue as this is CLI app, not a response/request one.
Overriding variable like this is confusing. Personally I'd extract it to own method too. E.g.
createReturnNode()with early returns.But current state is also ok
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.
Not sure what do you mean by that. Can I leave it as it looks like at the moment (after today's changes)?