Skip to content

Commit 16c771d

Browse files
committed
Fix compatibility with PHP 7.3/nightly
As of PHP 7.3, using `continue` to target a `switch` control structure will throw an `E_WARNING`. Applying `continue` to a `switch` is equivalent to using `break` and more often than not, a `continue` targeting a higher level control structure is actually intended. To target the higher level control structure, a numeric argument has to be passed to `continue`. Refs: * php/php-src#3364 * https://wiki.php.net/rfc/continue_on_switch_deprecation This change has been recently committed to PHP itself and will break the build against `nightly` for the current `master` already. See: https://travis-ci.org/jrfnl/PHP_CodeSniffer/jobs/401533444 (this branch, but without commits, so equal to the current `master`). This PR fixes the instances of this in PHPCS. All these switches are nested in other control structures, but end the switch end the scope closer of the outer control structure, so using `break` in these cases would be equivalent to using `continue 2`. FYI: The PHPCompatibility standard will include a sniff to detect this in the near future.
1 parent 0e467f5 commit 16c771d

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/Files/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ public function getMethodParameters($stackPtr)
14081408
// If it's null, then there must be no parameters for this
14091409
// method.
14101410
if ($currVar === null) {
1411-
continue;
1411+
continue 2;
14121412
}
14131413

14141414
$vars[$paramCount] = [];

src/Tokenizers/CSS.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ public function tokenize($string)
390390

391391
// Needs to be in the format "url(" for it to be a URL.
392392
if ($finalTokens[$x]['code'] !== T_OPEN_PARENTHESIS) {
393-
continue;
393+
continue 2;
394394
}
395395

396396
// Make sure the content isn't empty.
@@ -401,7 +401,7 @@ public function tokenize($string)
401401
}
402402

403403
if ($finalTokens[$y]['code'] === T_CLOSE_PARENTHESIS) {
404-
continue;
404+
continue 2;
405405
}
406406

407407
if (PHP_CODESNIFFER_VERBOSITY > 1) {

src/Tokenizers/Tokenizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ private function createTokenMap()
743743
}
744744
break;
745745
default:
746-
continue;
746+
continue 2;
747747
}//end switch
748748
}//end for
749749

0 commit comments

Comments
 (0)