Skip to content

Commit 5321431

Browse files
author
Vincent Langlet
committed
🐛 Fix rules
1 parent 960c9df commit 5321431

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Symfony3Custom/Sniffs/Formatting/ConditionalReturnOrThrowSniff.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,25 @@ public function process(File $phpcsFile, $stackPtr)
6767
$condition = $phpcsFile->findNext($this->conditions, $stackPtr + 1);
6868

6969
if (false !== $condition) {
70-
$next = $phpcsFile->findNext($this->openers, $stackPtr + 1);
70+
$start = $stackPtr;
71+
$end = $condition;
7172

72-
if (false !== $next) {
73-
$err = (isset($tokens[$condition]['scope_closer']) && isset($tokens[$next]['scope_opener']))
74-
? $tokens[$condition]['scope_closer'] < $tokens[$next]['scope_opener']
75-
: $tokens[$condition]['line'] <= $tokens[$next]['line'];
76-
} else {
73+
$next = $phpcsFile->findNext($this->openers, $start + 1, $end);
74+
while (false !== $next) {
75+
if ($tokens[$condition]['level'] >= $tokens[$next]['level']) {
76+
$err = false;
77+
break;
78+
}
79+
80+
$start = $next;
81+
$next = $phpcsFile->findNext($this->openers, $start + 1, $end);
82+
}
83+
84+
if (!isset($err)) {
7785
$err = $tokens[$condition]['level'] === $tokens[$opener]['level'];
7886
}
7987

80-
if ($err) {
88+
if (true === $err) {
8189
$phpcsFile->addError(
8290
'Do not use else, elseif, break after if and case conditions which return or throw something',
8391
$condition,

Symfony3Custom/Tests/Formatting/ConditionalReturnOrThrowUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class Test
7474
} else {
7575
$a = 1;
7676
}
77+
78+
if ($a = 1) {
79+
$b = 2;
80+
}
7781
}
7882
}
7983

0 commit comments

Comments
 (0)