Skip to content

[DeadCode] Add RemoveDoubleSelfAssignRector#8203

Merged
TomasVotruba merged 1 commit into
mainfrom
remove-double-self-assign-rector
Jul 23, 2026
Merged

[DeadCode] Add RemoveDoubleSelfAssignRector#8203
TomasVotruba merged 1 commit into
mainfrom
remove-double-self-assign-rector

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds a dead-code rule that removes a duplicated self-assign of the same variable in a chained assignment.

-$validator = $validator = Validation::createValidator();
+$validator = Validation::createValidator();

Only triggers when both sides of the outer assign are the same Variable; a real chained assign to different variables ($first = $second = ...) is skipped.

@TomasVotruba
TomasVotruba merged commit 919fc0e into main Jul 23, 2026
66 checks passed
@TomasVotruba
TomasVotruba deleted the remove-double-self-assign-rector branch July 23, 2026 07:00

namespace Rector\Tests\DeadCode\Rector\Assign\RemoveDoubleSelfAssignRector\Fixture;

$validator = $validator = createValidator();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe worth adding support for $validator = $another = $validator = createValidator();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Care to PR?

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