New sniff to remove redundant empty on loop vars#2840
Conversation
📝 WalkthroughWalkthroughThis PR systematically replaces Changes
Possibly related PRs
Poem
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnLoopVariableSniff.php`:
- Around line 186-207: The current wasVariableReassigned function only detects
simple T_EQUAL and misses compound assignments and increments/decrements; update
it to also treat compound-assignment tokens (e.g. T_PLUS_EQUAL, T_MINUS_EQUAL,
T_MUL_EQUAL, T_DIV_EQUAL, T_CONCAT_EQUAL, T_MOD_EQUAL, T_POW_EQUAL, T_AND_EQUAL,
T_OR_EQUAL, T_XOR_EQUAL, T_SL_EQUAL, T_SR_EQUAL) as reassignment when they
appear immediately after the variable, and detect increment/decrement tokens
(T_INC, T_DEC) when they appear immediately before or after the variable;
implement this by examining the next non-whitespace token for any
assignment/compound-assignment token and the previous/next non-whitespace token
for T_INC/T_DEC (and treat =&/reference-style assignments similarly if present)
inside wasVariableReassigned to return true for these cases.
🧹 Nitpick comments (1)
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnLoopVariableSniff.php (1)
220-220: Unused parameter$variableNameinapplyFixmethod.The
$variableNameparameter is passed but never used. The method independently locates the variable token usingfindNext. Consider removing this parameter to clean up the API.Proposed fix
Update the method signature and call site:
-private function applyFix( File $phpcsFile, $emptyToken, $openParen, $closeParen, $variableName ) { +private function applyFix( File $phpcsFile, $emptyToken, $openParen, $closeParen ) {And at line 110:
-$this->applyFix( $phpcsFile, $stackPtr, $openParen, $closeParen, $variableName ); +$this->applyFix( $phpcsFile, $stackPtr, $openParen, $closeParen );
…t_empty_on_loop_vars New sniff to remove redundant empty on loop vars
Summary by CodeRabbit
New Features
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.