Skip to content

Commit

Permalink
Do not mutate coalesce operator in the Assignment mutator (we have in…
Browse files Browse the repository at this point in the history
…dependent AssignCoalesce mutator) (#1739)
  • Loading branch information
sidz committed Oct 16, 2022
1 parent fbd8c44 commit 822e8f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mutator/Arithmetic/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public function mutate(Node $node): iterable

public function canMutate(Node $node): bool
{
return $node instanceof Node\Expr\AssignOp;
return $node instanceof Node\Expr\AssignOp && !$node instanceof Node\Expr\AssignOp\Coalesce;
}
}
9 changes: 9 additions & 0 deletions tests/phpunit/Mutator/Arithmetic/AssignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,14 @@ public function mutationsProvider(): iterable
$a = $b;
PHP
];

yield 'It does not mutate Coalesce operator' => [
<<<'PHP'
<?php
$a ??= $b;
PHP
,
];
}
}

0 comments on commit 822e8f1

Please sign in to comment.