Skip to content

Commit 340a0f0

Browse files
committed
Generic/DisallowYodaConditions: remove two unreachable conditions
The first condition is unreachable because PHPCS will never call DisallowYodaConditionsSniff::process() if there is no non-empty token before a comparison token. Even if the file contains a syntax error, there must be at least a PHP opening tag before the comparison token for the method to be called. The second condition is unreachable because at this point in the code there will always be at least two non-empty tokens before the comparison token. If there is only one, it must be a PHP opening tag and, in this case, the method will bail before reaching the code that sets the `$prevIndex` variable.
1 parent 61ae512 commit 340a0f0

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public function process(File $phpcsFile, $stackPtr)
5757
T_CONSTANT_ENCAPSED_STRING,
5858
];
5959

60-
if ($previousIndex === false
61-
|| in_array($tokens[$previousIndex]['code'], $relevantTokens, true) === false
62-
) {
60+
if (in_array($tokens[$previousIndex]['code'], $relevantTokens, true) === false) {
6361
return;
6462
}
6563

@@ -71,9 +69,6 @@ public function process(File $phpcsFile, $stackPtr)
7169
}
7270

7371
$prevIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($previousIndex - 1), null, true);
74-
if ($prevIndex === false) {
75-
return;
76-
}
7772

7873
if (in_array($tokens[$prevIndex]['code'], Tokens::$arithmeticTokens, true) === true) {
7974
return;

0 commit comments

Comments
 (0)