diff --git a/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php b/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php index 50f382f959..f35323c006 100644 --- a/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php +++ b/CodeSniffer/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php @@ -179,7 +179,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) if (isset($tokens[$end]['scope_opener']) === true) { $type = $tokens[$end]['code']; $end = $tokens[$end]['scope_closer']; - if ($type === T_DO || $type === T_IF || $type === T_ELSEIF) { + if ($type === T_DO || $type === T_IF || $type === T_ELSEIF || $type === T_TRY) { $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), null, true); if ($next === false) { break; @@ -200,6 +200,11 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) if ($type === T_DO && $nextType === T_WHILE) { $end = $phpcsFile->findNext(T_SEMICOLON, ($next + 1)); } + + // Account for TRY... CATCH statements. + if ($type === T_TRY && $nextType === T_CATCH) { + $end = $tokens[$next]['scope_closer']; + } }//end if if ($tokens[$end]['code'] !== T_END_HEREDOC diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc index 808c396873..bd5ea6b1b4 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc @@ -186,3 +186,9 @@ if ($a && $a === Foo::VARIABLE && ($a === Foo::METHOD || $a === Foo::FUNCTION)) echo 'hi'; $out = array_map(function ($test) { if ($test) return 1; else return 2; }, $input); // comment + +if (true) + try { + } + catch(Exception $e) { + } diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed index c2ed6c2be4..b0498a7f8a 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.inc.fixed @@ -212,3 +212,10 @@ if ($a && $a === Foo::VARIABLE && ($a === Foo::METHOD || $a === Foo::FUNCTION)) $out = array_map(function ($test) { if ($test) { return 1; } else { return 2; } }, $input); // comment + +if (true) { + try { + } + catch(Exception $e) { + } +} diff --git a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php index 0a9d7ff6ea..c09c8b25c4 100644 --- a/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php +++ b/CodeSniffer/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.php @@ -80,6 +80,7 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.inc') 178 => 1, 185 => 1, 188 => 2, + 190 => 1, ); break; case 'InlineControlStructureUnitTest.js': diff --git a/package.xml b/package.xml index 7e3076f548..c6115357a8 100644 --- a/package.xml +++ b/package.xml @@ -40,6 +40,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - Fixed bug #1246 : A mix of USE statements with and without braces can cause the tokenizer to mismatch brace tokens -- Thanks to MichaƂ Bundyra for the patch - Fixed bug #1252 : Squiz.Strings.ConcatenationSpacing fix creates syntax error when joining a number to a string + - Fixed bug #1253 : Generic.ControlStructures.InlineControlStructure fix creates syntax error fixing if-try/catch - Fixed bug #1257 : Double dash in CSS class name can lead to "Named colours are forbidden" false positives