-
-
Notifications
You must be signed in to change notification settings - Fork 430
Fix foreach key evaluation for SimplifyForeachToArrayFilterRector. #3100
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
Fix foreach key evaluation for SimplifyForeachToArrayFilterRector. #3100
Conversation
24de7a4 to
22ab55d
Compare
rules/CodeQuality/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php
Outdated
Show resolved
Hide resolved
| $parentArrayDimFetch = $keyVarUsage[0]->getAttribute(AttributeKey::PARENT_NODE); | ||
| if (! $parentArrayDimFetch instanceof ArrayDimFetch) { | ||
| return true; | ||
| } | ||
|
|
||
| return $parentArrayDimFetch->dim !== $keyVarUsage[0]; |
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 tried locally, you can actually use ReadExprAnalyzer service:
| $parentArrayDimFetch = $keyVarUsage[0]->getAttribute(AttributeKey::PARENT_NODE); | |
| if (! $parentArrayDimFetch instanceof ArrayDimFetch) { | |
| return true; | |
| } | |
| return $parentArrayDimFetch->dim !== $keyVarUsage[0]; | |
| return ! $this->readExprAnalyzer->isExprRead(current($keyVarUsage)); |
You need to inject the constructor with Rector\ReadWrite\NodeAnalyzer\ReadExprAnalyzer service.
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.
22ab55d to
76fa681
Compare
|
Thank you @Wohlie |
|
Thanks @samsonasik for fixing! |
Fix rectorphp/rector#7592
The issue rectorphp/rector#7570 can be changed to improvement, see expected result.