Generic_Sniffs_CodeAnalysis_JumbledIncrementerSniff
in package
implements
PHP_CodeSniffer_Sniff
Detects incrementer jumbling in for loops.
This rule is based on the PMD rule catalog. The jumbling incrementer sniff detects the usage of one and the same incrementer into an outer and an inner loop. Even it is intended this is confusing code.
class Foo
{
public function bar($x)
{
for ($i = 0; $i < 10; $i++)
{
for ($k = 0; $k < 20; $i++)
{
echo 'Hello';
}
}
}
}
Tags
Interfaces, Classes and Traits
- PHP_CodeSniffer_Sniff
- Represents a PHP_CodeSniffer sniff for sniffing coding standards.
Table of Contents
- process() : void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, int>
- Registers the tokens that this sniff wants to listen for.
- findIncrementers() : array<string|int, string>
- Get all used variables in the incrementer part of a for statement.
Methods
process()
Processes this test, when one of its tokens is encountered.
public
process(PHP_CodeSniffer_File $phpcsFile, int $stackPtr) : void
Parameters
- $phpcsFile : PHP_CodeSniffer_File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Return values
void —register()
Registers the tokens that this sniff wants to listen for.
public
register() : array<string|int, int>
Return values
array<string|int, int> —findIncrementers()
Get all used variables in the incrementer part of a for statement.
protected
findIncrementers(array<string|int, mixed> $tokens, array<string|int, mixed> $token) : array<string|int, string>
Parameters
- $tokens : array<string|int, mixed>
- $token : array<string|int, mixed>
Return values
array<string|int, string> —List of all found incrementer variables.