Skip to content

fix: NoUselessElseFixer - handle conditional symbol declarations#9347

Merged
keradus merged 5 commits intoPHP-CS-Fixer:masterfrom
gharlan:fix-no-useless-else
Jan 16, 2026
Merged

fix: NoUselessElseFixer - handle conditional symbol declarations#9347
keradus merged 5 commits intoPHP-CS-Fixer:masterfrom
gharlan:fix-no-useless-else

Conversation

@gharlan
Copy link
Copy Markdown
Member

@gharlan gharlan commented Jan 13, 2026

fixes #9340

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 14, 2026

Coverage Status

coverage: 93.007% (-0.001%) from 93.008%
when pulling 7f6596f on gharlan:fix-no-useless-else
into 571e6b2 on PHP-CS-Fixer:master.

Copy link
Copy Markdown
Member

@keradus keradus left a comment

Choose a reason for hiding this comment

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

nice, thank you


// clean up `else` if possible
if ($this->isSuperfluousElse($tokens, $index)) {
if ($this->isSuperfluousElse($tokens, $index) && !$this->containsNamedSymbolDeclaration($tokens, $index)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please put a comment why we don't remove the else when symbol declared conditionally

@keradus keradus merged commit dcefc52 into PHP-CS-Fixer:master Jan 16, 2026
6 checks passed
@gharlan gharlan deleted the fix-no-useless-else branch January 19, 2026 16:32
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.

no_useless_else and conditional class declaration

3 participants