Skip to content

Conversation

@solverat
Copy link
Contributor

@solverat solverat commented Jan 8, 2026

This PR fixes the rule ForeachItemsAssignToEmptyArrayToAssignRector, which currently ignores array modifications in skipped foreach loops, leading to incorrect direct assignments that overwrite previously collected data.

Fixes rectorphp/rector#9587 and probably rectorphp/rector#9534.

Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

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

please add fixture for it at directory

https://github.com/rectorphp/rector-src/tree/main/rules-tests/CodeQuality/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector/Fixture

you can make file with skip_ prefix like in the fixture directory

@solverat solverat requested a review from samsonasik January 8, 2026 19:30
Copy link
Member

@samsonasik samsonasik left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@TomasVotruba TomasVotruba merged commit cad967d into rectorphp:main Jan 9, 2026
58 checks passed
@TomasVotruba
Copy link
Member

Thank you 👍

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.

Incorrect behavior of ForeachItemsAssignToEmptyArrayToAssignRector

3 participants