Skip to content

Commit bd06327

Browse files
committed
RequireShortTernaryOperatorSniff: Fixed false positive
1 parent af7db0b commit bd06327

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

SlevomatCodingStandard/Sniffs/ControlStructures/RequireShortTernaryOperatorSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function process(File $phpcsFile, $inlineThenPointer): void
106106
/** @var int $pointerBeforeCondition */
107107
$pointerBeforeCondition = TokenHelper::findPreviousEffective($phpcsFile, $conditionStartPointer - 1);
108108

109+
if (in_array($tokens[$pointerBeforeCondition]['code'], Tokens::$booleanOperators, true)) {
110+
return;
111+
}
112+
109113
if (in_array($tokens[$pointerBeforeCondition]['code'], Tokens::$comparisonTokens, true)) {
110114
// Yoda condition
111115
return;

tests/Sniffs/ControlStructures/data/requireShortTernaryOperatorNoErrors.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
$x = true ?: false;
3838

39+
$x = $xx && $yy ? $yy : false;
40+
3941
class Whatever
4042
{
4143

0 commit comments

Comments
 (0)