55use Infection \Mutator \Definition ;
66use Infection \Mutator \Mutator ;
77use Infection \Mutator \MutatorCategory ;
8+ use Infection \PhpParser \Visitor \ParentConnector ;
89use LogicException ;
910use PhpParser \Node ;
1011use function in_array ;
1112
1213/**
13- * @implements Mutator<Node\Expr\MethodCall>
14+ * @implements Mutator<Node\Expr\MethodCall|Node\Expr\BooleanNot >
1415 */
1516final class TrinaryLogicMutator implements Mutator
1617{
@@ -38,6 +39,18 @@ public function getName(): string
3839
3940 public function canMutate (Node $ node ): bool
4041 {
42+ if ($ node instanceof Node \Expr \MethodCall) {
43+ $ parentNode = ParentConnector::getParent ($ node );
44+
45+ if ($ parentNode instanceof Node \Expr \BooleanNot) {
46+ return false ;
47+ }
48+ }
49+
50+ if ($ node instanceof Node \Expr \BooleanNot) {
51+ $ node = $ node ->expr ;
52+ }
53+
4154 if (!$ node instanceof Node \Expr \MethodCall) {
4255 return false ;
4356 }
@@ -55,6 +68,25 @@ public function canMutate(Node $node): bool
5568
5669 public function mutate (Node $ node ): iterable
5770 {
71+ if ($ node instanceof Node \Expr \BooleanNot) {
72+ $ node = $ node ->expr ;
73+ if (!$ node instanceof Node \Expr \MethodCall) {
74+ throw new LogicException ();
75+ }
76+
77+ if (!$ node ->name instanceof Node \Identifier) {
78+ throw new LogicException ();
79+ }
80+
81+ if ($ node ->name ->name === 'yes ' ) {
82+ yield new Node \Expr \MethodCall ($ node ->var , 'no ' );
83+ } else {
84+ yield new Node \Expr \MethodCall ($ node ->var , 'yes ' );
85+ }
86+
87+ return ;
88+ }
89+
5890 if (!$ node ->name instanceof Node \Identifier) {
5991 throw new LogicException ();
6092 }
0 commit comments