Skip to content

Commit

Permalink
Fixed bug #787 : SpacingAfterDefaultBreak confused by multi-line stat…
Browse files Browse the repository at this point in the history
…ements
  • Loading branch information
gsherwood committed Nov 25, 2015
1 parent 85cbd46 commit e03eef1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->addError($error, $nextBreak, 'SpacingBeforeBreak');
}

$breakLine = $tokens[$nextBreak]['line'];
$nextLine = $tokens[$tokens[$stackPtr]['scope_closer']]['line'];
$semicolon = $phpcsFile->findNext(T_SEMICOLON, $nextBreak);
$semicolon = $phpcsFile->findEndOfStatement($nextBreak);
for ($i = ($semicolon + 1); $i < $tokens[$stackPtr]['scope_closer']; $i++) {
if ($tokens[$i]['type'] !== 'T_WHITESPACE') {
$nextLine = $tokens[$i]['line'];
Expand Down Expand Up @@ -231,7 +230,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}//end if
} else {
// Ensure the BREAK statement is not followed by a blank line.
if ($nextLine !== ($breakLine + 1)) {
if ($nextLine !== ($tokens[$semicolon]['line'] + 1)) {
$error = 'Blank lines are not allowed after the DEFAULT case\'s breaking statement';
$phpcsFile->addError($error, $nextBreak, 'SpacingAfterDefaultBreak');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,15 @@ switch ($foo) {
default:
throw new Exception();
}

switch ($foo) {
case 'bar':
throw new \Exception(
'bar'
);

default:
throw new \Exception(
'bar'
);
}
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- If both a phpcs.xml and phpcs.xml.dist file are present, the phpcs.xml file will be used
- Fixed bug #784 : $this->trait is seen as a T_TRAIT token
- Fixed bug #786 : Switch indent issue with short array notation
- Fixed bug #787 : SpacingAfterDefaultBreak confused by multi-line statements
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit e03eef1

Please sign in to comment.