Skip to content

Commit

Permalink
Merge branch 'feature/3345-generic-inlinecontrolstructures-bugfix-mul…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed May 27, 2021
2 parents 798ae54 + 59e161a commit 0aec4c3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,10 @@ public function process(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 || $type === T_TRY) {
if ($type === T_DO
|| $type === T_IF || $type === T_ELSEIF
|| $type === T_TRY || $type === T_CATCH || $type === T_FINALLY
) {
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
if ($next === false) {
break;
Expand All @@ -227,15 +230,20 @@ public function process(File $phpcsFile, $stackPtr)
continue;
}

// Account for TRY... CATCH/FINALLY statements.
if (($type === T_TRY
|| $type === T_CATCH
|| $type === T_FINALLY)
&& ($nextType === T_CATCH
|| $nextType === T_FINALLY)
) {
continue;
}

// Account for DO... WHILE conditions.
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'];
}
} else if ($type === T_CLOSURE) {
// There should be a semicolon after the closing brace.
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), null, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,22 @@ for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);

if ($this->valid(fn(): bool => 2 > 1)) {
}

// Issue 3345.
function testMultiCatch()
{
if (true)
try {
} catch (\LogicException $e) {
} catch (\Exception $e) {
}
}

function testFinally()
{
if (true)
try {
} catch (\LogicException $e) {
} finally {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,24 @@ for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);

if ($this->valid(fn(): bool => 2 > 1)) {
}

// Issue 3345.
function testMultiCatch()
{
if (true) {
try {
} catch (\LogicException $e) {
} catch (\Exception $e) {
}
}
}

function testFinally()
{
if (true) {
try {
} catch (\LogicException $e) {
} finally {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public function getErrorList($testFile='InlineControlStructureUnitTest.1.inc')
236 => 1,
238 => 1,
242 => 1,
260 => 1,
269 => 1,
];

case 'InlineControlStructureUnitTest.js':
Expand Down

0 comments on commit 0aec4c3

Please sign in to comment.