File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
rules-tests/CodeQuality/Rector/If_/SimplifyIfElseToTernaryRector/Fixture
rules/CodeQuality/Rector/If_ Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \CodeQuality \Rector \If_ \SimplifyIfElseToTernaryRector \Fixture ;
4+
5+ class WithAssign
6+ {
7+ public function run ()
8+ {
9+ if ($ a = $ this ->methodX ()) {
10+ $ this ->out = $ a ;
11+ } else {
12+ $ this ->out = $ this ->methodY ();
13+ }
14+ }
15+ }
16+
17+ ?>
18+ -----
19+ <?php
20+
21+ namespace Rector \Tests \CodeQuality \Rector \If_ \SimplifyIfElseToTernaryRector \Fixture ;
22+
23+ class WithAssign
24+ {
25+ public function run ()
26+ {
27+ $ this ->out = ($ a = $ this ->methodX ()) ? $ a : $ this ->methodY ();
28+ }
29+ }
30+
31+ ?>
Original file line number Diff line number Diff line change @@ -125,7 +125,7 @@ public function refactor(Node $node): ?Node
125125 return null ;
126126 }
127127
128- if ($ ternary ->cond instanceof BinaryOp) {
128+ if ($ ternary ->cond instanceof BinaryOp || $ ternary -> cond instanceof Assign ) {
129129 $ ternary ->cond ->setAttribute (AttributeKey::ORIGINAL_NODE , null );
130130 }
131131
You can’t perform that action at this time.
0 commit comments