Skip to content

Commit 3fdb041

Browse files
🐛 Fix return in try catch
1 parent 648174e commit 3fdb041

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

SymfonyCustom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ public function process(File $phpcsFile, $stackPtr)
5858
if ($opener
5959
&& isset($tokens[$opener]['scope_closer'])
6060
&& $stackPtr <= $tokens[$opener]['scope_closer']) {
61-
$isClosure = $phpcsFile->findPrevious(T_CLOSURE, $stackPtr, $opener);
6261

62+
$isClosure = $phpcsFile->findPrevious(T_CLOSURE, $stackPtr, $opener);
6363
if (false !== $isClosure) {
6464
return;
6565
}
6666

67+
$isTryCatch = $phpcsFile->findPrevious([T_TRY, T_CATCH], $stackPtr, $opener);
68+
if (false !== $isTryCatch) {
69+
return;
70+
}
71+
6772
$condition = $phpcsFile->findNext($this->conditions, $stackPtr + 1);
6873

6974
if (false !== $condition) {

SymfonyCustom/Tests/Formatting/ConditionalReturnOrThrowUnitTest.inc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,20 @@ class Test
7979
$b = 2;
8080
}
8181
}
82+
83+
public function ok()
84+
{
85+
if (false) {
86+
try {
87+
$a = 1;
88+
} catch (NumberParseException $e) {
89+
$a = 1;
90+
91+
return;
92+
}
93+
} else {
94+
$a = 1;
95+
}
96+
}
8297
}
8398

0 commit comments

Comments
 (0)