Browse Source

fix: `MultilineWhitespaceBeforeSemicolonsFixer` - do not produce syntax error when there is a meaningful token after semicolon (#8230)

Kuba Werłos 5 months ago
parent
commit
3e8101812e

+ 3 - 0
src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php

@@ -176,6 +176,9 @@ $object->method1()
         $lineEnding = $this->whitespacesConfig->getLineEnding();
         $lineEnding = $this->whitespacesConfig->getLineEnding();
 
 
         for ($index, $count = \count($tokens); $index < $count; ++$index) {
         for ($index, $count = \count($tokens); $index < $count; ++$index) {
+            if (!$tokens[$index]->isWhitespace() && !$tokens[$index]->isComment()) {
+                break;
+            }
             if (false !== strstr($tokens[$index]->getContent(), $lineEnding)) {
             if (false !== strstr($tokens[$index]->getContent(), $lineEnding)) {
                 return $index;
                 return $index;
             }
             }

+ 14 - 0
tests/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixerTest.php

@@ -1157,6 +1157,20 @@ switch ($foo) {
 }
 }
 ',
 ',
         ];
         ];
+
+        yield [
+            <<<'PHP'
+                <?php
+                $x->foo()
+                    ->bar()
+                ;$y = 42;
+                PHP,
+            <<<'PHP'
+                <?php
+                $x->foo()
+                    ->bar();$y = 42;
+                PHP,
+        ];
     }
     }
 
 
     /**
     /**