Skip to content

[CodeQuality] Skip SimplifyUselessVariableRector on commented-out code and inline concat - #8468

Merged
TomasVotruba merged 3 commits into
mainfrom
skip-useless-variable-comment-and-inline-concat
Sep 6, 2026
Merged

TomasVotruba merged 3 commits into
mainfrom
skip-useless-variable-comment-and-inline-concat

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Two changes to SimplifyUselessVariableRector:

  1. Skip when commented-out code between the assign and the return mentions the variable. Such code is often re-enabled later, so inlining the assign into the return removes the variable it relies on.
$pdf = curl_exec($ch);

// $url = ...;
// $pdf = curl_exec($ch);
// curl_close($ch);

return $pdf;
  1. Stop merging compound assigns (.=, +=, ...) into the return. Folding $xml .= '</RuleMessage>'; return $xml; into return $xml . '</RuleMessage>'; worsens readability. Only direct assigns are simplified now, so the only_direct_assign option and its non-direct branch are removed.

TomasVotruba and others added 3 commits September 6, 2026 09:17
…e and inline concat

Do not inline a variable when commented-out code between assign and return mentions it, as it may be re-enabled later. Also stop merging compound assigns (.=, += ...) into the return, which worsens readability; only direct assigns are simplified now.
The AssignOp direction was only used by SimplifyUselessVariableRector, which no longer merges compound assigns; the sole caller now passes a BinaryOp.
@TomasVotruba
TomasVotruba merged commit a5c7025 into main Sep 6, 2026
43 checks passed
@TomasVotruba
TomasVotruba deleted the skip-useless-variable-comment-and-inline-concat branch September 6, 2026 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants