Browse Source

fix: `NoUselessConcatOperatorFixer` - do not remove new line (#7759)

Kuba Werłos 1 year ago
parent
commit
65da2e7834

+ 1 - 1
src/Fixer/Operator/NoUselessConcatOperatorFixer.php

@@ -244,8 +244,8 @@ final class NoUselessConcatOperatorFixer extends AbstractFixer implements Config
             ],
         );
 
-        $tokens->clearTokenAndMergeSurroundingWhitespace($secondOperand['start']);
         $this->clearConcatAndAround($tokens, $concatOperatorIndex);
+        $tokens->clearTokenAndMergeSurroundingWhitespace($secondOperand['start']);
     }
 
     /**

+ 13 - 0
tests/Fixer/Operator/NoUselessConcatOperatorFixerTest.php

@@ -160,6 +160,19 @@ line 2 indent" ?>',
 ;
 ",
         ];
+
+        yield 'concat without linebreak, followed by one with linebreak' => [
+            <<<'PHP'
+                <?php
+                $foo = 'ab'
+                    . 'c';
+                PHP,
+            <<<'PHP'
+                <?php
+                $foo = 'a' . 'b'
+                    . 'c';
+                PHP,
+        ];
     }
 
     public function testWithConfigJuggling(): void