diff --git a/psalm.xml b/psalm.xml
index 7c69aab1c..493815a9f 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -14,4 +14,12 @@
+
+
+
+
+
+
+
+
diff --git a/src/Mutator/Operator/Concat.php b/src/Mutator/Operator/Concat.php
index b080180e5..26ca8fbd9 100644
--- a/src/Mutator/Operator/Concat.php
+++ b/src/Mutator/Operator/Concat.php
@@ -40,6 +40,7 @@
use Infection\Mutator\Mutator;
use Infection\Mutator\MutatorCategory;
use PhpParser\Node;
+use PhpParser\PrettyPrinter\Standard;
/**
* @internal
@@ -81,13 +82,19 @@ public static function getDefinition(): ?Definition
*/
public function mutate(Node $node): iterable
{
+ $printer = new Standard();
+
if ($node->left instanceof Node\Expr\BinaryOp\Concat) {
$left = new Node\Expr\BinaryOp\Concat($node->left->left, $node->right);
$right = $node->left->right;
-
- yield new Node\Expr\BinaryOp\Concat($left, $right);
} else {
- yield new Node\Expr\BinaryOp\Concat($node->right, $node->left);
+ [$left, $right] = [$node->right, $node->left];
+ }
+
+ $newNode = new Node\Expr\BinaryOp\Concat($left, $right);
+
+ if ($printer->prettyPrint([clone $node]) !== $printer->prettyPrint([$newNode])) {
+ yield $newNode;
}
}
diff --git a/tests/phpunit/Mutator/Operator/ConcatTest.php b/tests/phpunit/Mutator/Operator/ConcatTest.php
index ed4341634..856497418 100644
--- a/tests/phpunit/Mutator/Operator/ConcatTest.php
+++ b/tests/phpunit/Mutator/Operator/ConcatTest.php
@@ -154,5 +154,37 @@ public function mutationsProvider(): iterable
,
],
];
+
+ yield 'Does not flip the same variable' => [
+ <<<'PHP'
+ [
+ <<<'PHP'
+ [
+ <<<'PHP'
+