diff --git a/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php b/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php index 4fdeb6132a..acfbdf3591 100644 --- a/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php +++ b/CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/SwitchDeclarationSniff.php @@ -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']; @@ -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'); } diff --git a/CodeSniffer/Standards/Squiz/Tests/ControlStructures/SwitchDeclarationUnitTest.inc b/CodeSniffer/Standards/Squiz/Tests/ControlStructures/SwitchDeclarationUnitTest.inc index ad3ab2764d..5c71161425 100644 --- a/CodeSniffer/Standards/Squiz/Tests/ControlStructures/SwitchDeclarationUnitTest.inc +++ b/CodeSniffer/Standards/Squiz/Tests/ControlStructures/SwitchDeclarationUnitTest.inc @@ -303,3 +303,15 @@ switch ($foo) { default: throw new Exception(); } + +switch ($foo) { + case 'bar': + throw new \Exception( + 'bar' + ); + + default: + throw new \Exception( + 'bar' + ); +} diff --git a/package.xml b/package.xml index a3144475d9..7a813e7eba 100644 --- a/package.xml +++ b/package.xml @@ -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