Skip to content

Commit 0978ad7

Browse files
committed
Add T_BOOLEAN_OR to blacklist in case of "and" and T_LOGICAL_XOR in case of "or"
1 parent d9e6ac0 commit 0978ad7

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

CodeSniffer/Standards/Squiz/Sniffs/Operators/ValidLogicalOperatorsSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
9898
T_INLINE_ELSE,
9999
);
100100

101+
// Extend blacklist depending on which operator is being processed.
102+
if ($tokens[$stackPtr]['code'] === T_LOGICAL_OR) {
103+
$blackList[] = T_LOGICAL_XOR;
104+
} else if ($tokens[$stackPtr]['code'] === T_LOGICAL_AND) {
105+
$blackList[] = T_BOOLEAN_OR;
106+
}
107+
101108
$start = $phpcsFile->findStartOfStatement($stackPtr);
102109
$end = $phpcsFile->findEndOfStatement($stackPtr);
103110

CodeSniffer/Standards/Squiz/Tests/Operators/ValidLogicalOperatorsUnitTest.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ $foo = ($a and ($b ?? $c) ?? $d);
4949
$foo = ($a and ($b ?? $c) or $d);
5050
$foo = ($a and ($b ?? $c) or $d ?? $e);
5151

52+
$foo = ($a and $b || $c);
53+
$foo = ($a or $b xor $c);
54+
$foo = ($a and $b or $c);
55+
5256
?>

CodeSniffer/Standards/Squiz/Tests/Operators/ValidLogicalOperatorsUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public function getErrorList()
6767
48 => 1,
6868
49 => 2,
6969
50 => 2,
70+
52 => 1,
71+
53 => 1,
72+
54 => 2,
7073
);
7174

7275
}//end getErrorList()

0 commit comments

Comments
 (0)