Skip to content

Commit 2501460

Browse files
committed
Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff
1 parent bc7623a commit 2501460

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

CodeSniffer/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
201201
}//end if
202202

203203
// Only want to check multi-keyword structures from here on.
204-
if ($tokens[$stackPtr]['code'] === T_TRY
205-
|| $tokens[$stackPtr]['code'] === T_DO
206-
) {
204+
if ($tokens[$stackPtr]['code'] === T_DO) {
207205
$closer = $tokens[$stackPtr]['scope_closer'];
208206
} else if ($tokens[$stackPtr]['code'] === T_ELSE
209207
|| $tokens[$stackPtr]['code'] === T_ELSEIF
208+
|| $tokens[$stackPtr]['code'] === T_CATCH
210209
) {
211210
$closer = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
212211
if ($closer === false || $tokens[$closer]['code'] !== T_CLOSE_CURLY_BRACKET) {

CodeSniffer/Standards/Squiz/Tests/ControlStructures/ControlSignatureUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,13 @@ elseif ($a == 6) :
144144
else :
145145
echo "a is neither 5 nor 6";
146146
endif;
147+
148+
try {
149+
// try body
150+
}
151+
catch (FirstExceptionType $e) {
152+
// catch body
153+
}
154+
catch (OtherExceptionType $e) {
155+
// catch body
156+
}

CodeSniffer/Standards/Squiz/Tests/ControlStructures/ControlSignatureUnitTest.inc.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,11 @@ elseif ($a == 6) :
147147
else :
148148
echo "a is neither 5 nor 6";
149149
endif;
150+
151+
try {
152+
// try body
153+
} catch (FirstExceptionType $e) {
154+
// catch body
155+
} catch (OtherExceptionType $e) {
156+
// catch body
157+
}

CodeSniffer/Standards/Squiz/Tests/ControlStructures/ControlSignatureUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ public function getErrorList($testFile='ControlSignatureUnitTest.inc')
7373
$errors[122] = 1;
7474
$errors[130] = 2;
7575
$errors[134] = 1;
76+
$errors[150] = 1;
77+
$errors[153] = 1;
7678
}
77-
79+
7880
return $errors;
7981

8082
}//end getErrorList()

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4545
- Fixed bug #515 : Spaces in JS block incorrectly flagged as indentation error
4646
- Fixed bug #523 : Generic ScopeIndent errors for IF in FINALLY
4747
- Fixed bug #527 : Closure inside IF statement is not tokenized correctly
48+
- Fixed bug #551 : Multiple catch blocks not checked in Squiz.ControlStructures.ControlSignature sniff
4849
</notes>
4950
<contents>
5051
<dir name="/">

0 commit comments

Comments
 (0)