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 @@ + +----- + 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