StandaloneLinePromotedPropertyFixer: properly deal with attributes. #78
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.
Claude Code (AI) : explanation of the two changes
What it does: When iterating backward through constructor parameters, the code needs to check each token.
The bug: The token was captured in a variable BEFORE skipping over nested blocks, but checked AFTER skipping. So it was checking the wrong token.
The fix: Simply moved 2 lines - now the token variable is assigned AFTER skipping, so it always examines the correct token.
What it does: When going backward through tokens, it skips over "blocks" (parentheses, arrays, etc.) so commas inside those blocks aren't treated as parameter separators.
The bug: It wasn't skipping attribute blocks like #[JMS\Expose, JMS\Type('integer')], so the comma inside was incorrectly treated as a parameter separator.
The fix:
The findAttributeStart() is just a 10-line loop that searches backward until it finds T_ATTRIBUTE (the #[ token). I could have used more complex existing infrastructure, but a simple backward search is the most straightforward solution.
What I did (simple approach):
Alternative using existing infrastructure:
The codebase already has BlockFinder (injected in the constructor) that knows how to find attribute blocks:
Why I didn't use it:
Looking at BlockFinder::findInTokensByEdge() (lines 40-90 in BlockFinder.php), it's designed to be called on opening tokens like (, [, {, or specific kinds like T_ATTRIBUTE, T_FUNCTION, etc. When
called on a closing ], it would treat it as an array bracket, not an attribute bracket.
So I'd need to add special logic or modify BlockFinder, which would be more invasive. The simple backward loop is more minimalist and self-contained.