File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed
rules-tests/DeadCode/Rector/Stmt/RemoveNextSameValueConditionRector/Fixture
rules/DeadCode/Rector/Stmt Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DeadCode \Rector \Stmt \RemoveNextSameValueConditionRector \Fixture ;
4+
5+ final class MergeComment
6+ {
7+ public function __construct (array $ items )
8+ {
9+ $ count = 100 ;
10+
11+ // 1
12+ if ($ items === []) {
13+ $ count = 0 ;
14+ }
15+
16+ // 2
17+ if ($ items === []) {
18+ return $ count ;
19+ }
20+ }
21+ }
22+
23+ ?>
24+ -----
25+ <?php
26+
27+ namespace Rector \Tests \DeadCode \Rector \Stmt \RemoveNextSameValueConditionRector \Fixture ;
28+
29+ final class MergeComment
30+ {
31+ public function __construct (array $ items )
32+ {
33+ $ count = 100 ;
34+
35+ // 1
36+ // 2
37+ if ($ items === []) {
38+ $ count = 0 ;
39+ return $ count ;
40+ }
41+ }
42+ }
43+
44+ ?>
Original file line number Diff line number Diff line change 99use PhpParser \Node \Stmt \Else_ ;
1010use PhpParser \Node \Stmt \If_ ;
1111use Rector \DeadCode \SideEffect \SideEffectNodeDetector ;
12+ use Rector \NodeTypeResolver \Node \AttributeKey ;
1213use Rector \PhpParser \Enum \NodeGroup ;
1314use Rector \PhpParser \Node \BetterNodeFinder ;
1415use Rector \Rector \AbstractRector ;
@@ -127,6 +128,10 @@ public function refactor(Node $node): ?Node
127128 continue ;
128129 }
129130
131+ $ stmt ->setAttribute (AttributeKey::COMMENTS , array_merge (
132+ $ stmt ->getAttribute (AttributeKey::COMMENTS ) ?? [],
133+ $ nextStmt ->getAttribute (AttributeKey::COMMENTS ) ?? []
134+ ));
130135 $ stmt ->stmts = array_merge ($ stmt ->stmts , $ nextStmt ->stmts );
131136
132137 // remove next node
You can’t perform that action at this time.
0 commit comments