Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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