Skip to content

Commit 80059d6

Browse files
committed
Generic/InlineControlStructure: remove unreachable if condition
Commit e1b9595 changed the InlineControlStructure sniff to make it bail early for all control structures without a body (before the sniff did that only for `while` and `for`). Before commit e1b9595, `$nextNonEmpty` could be `false` as there were some scenarios where there would be no non-empty tokens after the `$stackPtr` or after the `parenthesis_closer`. This is the case for the `else` without a body in InlineControlStructureUnitTest.2.inc and the `if` without a body in InlineControlStructureUnitTest.5.inc. After commit e1b9595, `$nextNonEmpty` cannot be `false` anymore as cases where there are no non-empty tokens are handled before this variable is set. This happens either in line 83 when `$nextTokenIndex` is set or line 98 when `$nextTokenIndex` is not set (a control structure that is not `T_ELSE` or `T_DO` and is missing the parenthesis closer).
1 parent 960d09c commit 80059d6

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ public function process(File $phpcsFile, int $stackPtr)
115115
}
116116

117117
$nextNonEmpty = $phpcsFile->findNext(Tokens::EMPTY_TOKENS, ($start + 1), null, true);
118-
if ($nextNonEmpty === false) {
119-
// Live coding or parse error.
120-
return;
121-
}
122118

123119
if ($tokens[$nextNonEmpty]['code'] === T_OPEN_CURLY_BRACKET
124120
|| $tokens[$nextNonEmpty]['code'] === T_COLON

0 commit comments

Comments
 (0)