Skip to content

Commit

Permalink
Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlSt…
Browse files Browse the repository at this point in the history
…ructures.ControlSignature sniff
  • Loading branch information
gsherwood committed Apr 15, 2015
1 parent bc7623a commit 2501460
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}//end if

// Only want to check multi-keyword structures from here on.
if ($tokens[$stackPtr]['code'] === T_TRY
|| $tokens[$stackPtr]['code'] === T_DO
) {
if ($tokens[$stackPtr]['code'] === T_DO) {
$closer = $tokens[$stackPtr]['scope_closer'];
} else if ($tokens[$stackPtr]['code'] === T_ELSE
|| $tokens[$stackPtr]['code'] === T_ELSEIF
|| $tokens[$stackPtr]['code'] === T_CATCH
) {
$closer = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,13 @@ elseif ($a == 6) :
else :
echo "a is neither 5 nor 6";
endif;

try {
// try body
}
catch (FirstExceptionType $e) {
// catch body
}
catch (OtherExceptionType $e) {
// catch body
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,11 @@ elseif ($a == 6) :
else :
echo "a is neither 5 nor 6";
endif;

try {
// try body
} catch (FirstExceptionType $e) {
// catch body
} catch (OtherExceptionType $e) {
// catch body
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public function getErrorList($testFile='ControlSignatureUnitTest.inc')
$errors[122] = 1;
$errors[130] = 2;
$errors[134] = 1;
$errors[150] = 1;
$errors[153] = 1;
}

return $errors;

}//end getErrorList()
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #515 : Spaces in JS block incorrectly flagged as indentation error
- Fixed bug #523 : Generic ScopeIndent errors for IF in FINALLY
- Fixed bug #527 : Closure inside IF statement is not tokenized correctly
- Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit 2501460

Please sign in to comment.