From 2f2394ce235e717735fdf2371baf2a05bb48d0bc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 6 Jan 2026 08:19:45 +0700 Subject: [PATCH 1/2] [DeadCode] Merge comment on RemoveNextSameValueConditionRector --- .../Fixture/merge_comment.php.inc | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 rules-tests/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector/Fixture/merge_comment.php.inc diff --git a/rules-tests/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector/Fixture/merge_comment.php.inc b/rules-tests/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector/Fixture/merge_comment.php.inc new file mode 100644 index 00000000000..7a1ea0e9f10 --- /dev/null +++ b/rules-tests/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector/Fixture/merge_comment.php.inc @@ -0,0 +1,44 @@ + +----- + From bf4ccfbc35ebf30cb57455854c28315efcc07536 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 6 Jan 2026 08:23:13 +0700 Subject: [PATCH 2/2] fix --- .../Rector/Stmt/RemoveNextSameValueConditionRector.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php b/rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php index 25f91a2f187..bfb0a1485b8 100644 --- a/rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php +++ b/rules/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\If_; use Rector\DeadCode\SideEffect\SideEffectNodeDetector; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Enum\NodeGroup; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\Rector\AbstractRector; @@ -127,6 +128,10 @@ public function refactor(Node $node): ?Node continue; } + $stmt->setAttribute(AttributeKey::COMMENTS, array_merge( + $stmt->getAttribute(AttributeKey::COMMENTS) ?? [], + $nextStmt->getAttribute(AttributeKey::COMMENTS) ?? [] + )); $stmt->stmts = array_merge($stmt->stmts, $nextStmt->stmts); // remove next node