File tree Expand file tree Collapse file tree
rules-tests/DeadCode/Rector/Ternary/RemoveUselessTernaryRector/Fixture
rules/DeadCode/Rector/Ternary Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DeadCode \Rector \Ternary \RemoveUselessTernaryRector \Fixture ;
4+
5+ class SkipNegatedCond
6+ {
7+ public function go (bool $ value )
8+ {
9+ return ! $ value ?: false ;
10+ }
11+ }
Original file line number Diff line number Diff line change 77use PhpParser \Node ;
88use PhpParser \Node \Expr ;
99use PhpParser \Node \Expr \Array_ ;
10+ use PhpParser \Node \Expr \BooleanNot ;
1011use PhpParser \Node \Expr \Ternary ;
1112use PhpParser \Node \Scalar \Int_ ;
1213use PHPStan \Type \ArrayType ;
@@ -65,6 +66,12 @@ public function refactor(Node $node): ?Node
6566 return null ;
6667 }
6768
69+ // if condition is negated
70+ // switch negated ternary condition via SwitchNegatedTernaryRector for that
71+ if ($ node ->cond instanceof BooleanNot) {
72+ return null ;
73+ }
74+
6875 $ nativeType = $ this ->nodeTypeResolver ->getNativeType ($ node ->cond );
6976 if ($ nativeType instanceof BooleanType && $ this ->valueResolver ->isFalse ($ node ->else )) {
7077 return $ node ->cond ;
You can’t perform that action at this time.
0 commit comments