Skip to content

[dead-code] Add RemoveNextSameValueConditionRector#7525

Merged
TomasVotruba merged 3 commits into
mainfrom
tv-double-condition
Nov 27, 2025
Merged

[dead-code] Add RemoveNextSameValueConditionRector#7525
TomasVotruba merged 3 commits into
mainfrom
tv-double-condition

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

@TomasVotruba TomasVotruba commented Oct 21, 2025

If there are 2 conditions following each other, they have the same condition, without side effect, the first condition is already evaluated. The 2nd one can be removed:

public function __construct(array $items)
    {
        $count = 100;
        if ($items === []) {
            $count = 0;
-        }
-        if ($items === []) {
            return $count;
        }
    }

Spotted in b52ae95

@TomasVotruba TomasVotruba force-pushed the tv-double-condition branch 2 times, most recently from 3aa2d76 to e4e5268 Compare October 21, 2025 13:36
Copy link
Copy Markdown
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.

This need skip for re-assign variable if compared in condition, see

https://3v4l.org/9eTXd vs https://3v4l.org/qETF5

Comment thread rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php
@TomasVotruba
Copy link
Copy Markdown
Member Author

@samsonasik I've just rebased the PR in latest main. I'll merge as WIP.
Could you add those fixture you mention and include fix in new PR?

@samsonasik
Copy link
Copy Markdown
Member

I will try

@TomasVotruba TomasVotruba merged commit ce4f8ff into main Nov 27, 2025
52 checks passed
@TomasVotruba TomasVotruba deleted the tv-double-condition branch November 27, 2025 10:49
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 3, 2026

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants