NoDoubleNegativeSniff
in package
implements
Sniff
Detects double negation in code, which is effectively the same as a boolean cast, but with a much higher cognitive load.
The sniff will only autofix if the precedence change from boolean not to boolean cast will not cause a behavioural change (as it would with instanceof).
Tags
Table of Contents
Interfaces
Properties
- $operatorsWithLowerPrecedence : array<int|string, int|string>
- Operators with lower precedence than the not-operator.
Methods
- process() : int|void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, int|string>
- Returns an array of tokens this test wants to listen for.
- removeNotAndTrailingSpaces() : void
- Remove boolean not-operators and trailing whitespace after those, but don't remove comments or trailing whitespace after comments.
Properties
$operatorsWithLowerPrecedence
Operators with lower precedence than the not-operator.
private
array<int|string, int|string>
$operatorsWithLowerPrecedence
Used to determine when to stop searching for instanceof.
Tags
Methods
process()
Processes this test, when one of its tokens is encountered.
public
process(File $phpcsFile, int $stackPtr) : int|void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
register()
Returns an array of tokens this test wants to listen for.
public
register() : array<string|int, int|string>
Tags
Return values
array<string|int, int|string>removeNotAndTrailingSpaces()
Remove boolean not-operators and trailing whitespace after those, but don't remove comments or trailing whitespace after comments.
private
removeNotAndTrailingSpaces(File $phpcsFile, int $stackPtr, int $lastNot) : void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
- $lastNot : int
-
The position of the last boolean not token in the chain.