Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bug #1253 : Generic.ControlStructures.InlineControlStructure fi…
…x creates syntax error fixing if-try/catch
  • Loading branch information
gsherwood committed Jan 3, 2017
1 parent 90a07f1 commit be56d7d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Expand Up @@ -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) {
}
Expand Up @@ -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) {
}
}
Expand Up @@ -80,6 +80,7 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.inc')
178 => 1,
185 => 1,
188 => 2,
190 => 1,
);
break;
case 'InlineControlStructureUnitTest.js':
Expand Down
1 change: 1 addition & 0 deletions package.xml
Expand Up @@ -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
</notes>
<contents>
Expand Down

0 comments on commit be56d7d

Please sign in to comment.