Skip to content

Commit

Permalink
Fixed bug #3296 : PSR2.ControlStructures.SwitchDeclaration takes phpc…
Browse files Browse the repository at this point in the history
…s:ignore as content of case body
  • Loading branch information
gsherwood committed Apr 16, 2021
1 parent 14fbcc0 commit c0122e9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Expand Up @@ -186,7 +186,7 @@ public function process(File $phpcsFile, $stackPtr)
$nextCode = $this->findNextCase($phpcsFile, ($opener + 1), $nextCloser);
if ($nextCode !== false) {
$prevCode = $phpcsFile->findPrevious(T_WHITESPACE, ($nextCode - 1), $nextCase, true);
if ($tokens[$prevCode]['code'] !== T_COMMENT
if (isset(Tokens::$commentTokens[$tokens[$prevCode]['code']]) === false
&& $this->findNestedTerminator($phpcsFile, ($opener + 1), $nextCode) === false
) {
$error = 'There must be a comment when fall-through is intentional in a non-empty case body';
Expand Down
Expand Up @@ -331,3 +331,12 @@ switch ($foo) {
case 2:
return 2;
}

switch ($foo) {
case 1:
// phpcs:ignore
case 2:
return 1;
case 3:
return 2;
}
Expand Up @@ -334,3 +334,12 @@ switch ($foo) {
case 2:
return 2;
}

switch ($foo) {
case 1:
// phpcs:ignore
case 2:
return 1;
case 3:
return 2;
}

0 comments on commit c0122e9

Please sign in to comment.