DisallowStandalonePostIncrementDecrementSniff
in package
implements
Sniff
Disallow the use of post-in/decrements in stand-alone statements and discourage the use of multiple increment/decrement operators in a stand-alone statement.
Post-in/decrement returns the value and in/decrements afterwards. Pre-in/decrement in/decrements the value and returns afterwards. Using pre-in/decrement is more in line with the principle of least astonishment and prevents bugs when code gets moved around at a later point in time.
Tags
Table of Contents
Interfaces
Constants
- METRIC_NAME = 'In/decrement usage in stand-alone statements'
- Name of the metric.
Properties
- $allowedTokens : array<string|int, int|string>
- Tokens which can be expected in a stand-alone in/decrement statement.
Methods
- process() : int|void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, int|string>
- Registers the tokens that this sniff wants to listen for.
Constants
METRIC_NAME
Name of the metric.
public
string
METRIC_NAME
= 'In/decrement usage in stand-alone statements'
Tags
Properties
$allowedTokens
Tokens which can be expected in a stand-alone in/decrement statement.
private
array<string|int, int|string>
$allowedTokens
= [\T_VARIABLE => \T_VARIABLE]
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()
Registers the tokens that this sniff wants to listen for.
public
register() : array<string|int, int|string>