Browse Source

bug #5325 NoBreakCommentFixer - better throw handling (SpacePossum)

This PR was merged into the 2.16 branch.

Discussion
----------

NoBreakCommentFixer - better throw handling

closes https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/5322

Commits
-------

6e8c7b22b NoBreakCommentFixer - better throw handling
Dariusz Ruminski 4 years ago
parent
commit
eae6b9b27a

+ 1 - 1
src/Fixer/ControlStructure/NoBreakCommentFixer.php

@@ -150,7 +150,7 @@ switch ($foo) {
             if ($tokens[$i]->isGivenKind([T_THROW])) {
                 $previousIndex = $tokens->getPrevMeaningfulToken($i);
 
-                if ($previousIndex === $caseColonIndex || $tokens[$previousIndex]->equalsAny(['{', ';', [T_OPEN_TAG]])) {
+                if ($previousIndex === $caseColonIndex || $tokens[$previousIndex]->equalsAny(['{', ';', '}', [T_OPEN_TAG]])) {
                     $fallThrough = false;
                 }
 

+ 14 - 0
tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php

@@ -45,6 +45,7 @@ final class NoBreakCommentFixerTest extends AbstractFixerTestCase
         $this->fixer->configure([
             'comment_text' => 'no break',
         ]);
+
         $this->doTest($expected, $input);
     }
 
@@ -876,6 +877,19 @@ switch ($a) {
 }
                 ',
             ],
+            [
+                '<?php
+switch ($f) {
+    case 1:
+        if ($a) {
+            return "";
+        }
+
+        throw new $f();
+    case Z:
+        break;
+}',
+            ],
         ];
     }