function JumbledIncrementerSniff::findIncrementers
Get all used variables in the incrementer part of a for statement.
Parameters
array<int, array> $tokens Array with all code sniffer tokens.:
array<string, mixed> $token Current for loop token.:
Return value
string[] List of all found incrementer variables.
1 call to JumbledIncrementerSniff::findIncrementers()
- JumbledIncrementerSniff::process in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ CodeAnalysis/ JumbledIncrementerSniff.php - Processes this test, when one of its tokens is encountered.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ CodeAnalysis/ JumbledIncrementerSniff.php, line 108
Class
Namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysisCode
protected function findIncrementers(array $tokens, array $token) {
// Skip invalid statement.
if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
return [];
}
$start = ++$token['parenthesis_opener'];
$end = --$token['parenthesis_closer'];
$incrementers = [];
$semicolons = 0;
for ($next = $start; $next <= $end; ++$next) {
$code = $tokens[$next]['code'];
if ($code === T_SEMICOLON) {
++$semicolons;
}
else {
if ($semicolons === 2 && $code === T_VARIABLE) {
$incrementers[] = $tokens[$next]['content'];
}
}
}
return $incrementers;
}