function StaticThisUsageSniff::checkThisUsage
Check for $this variable usage between $next and $end tokens.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The current file being scanned.:
int $next The position of the next token to check.:
int $end The position of the last token to check.:
Return value
void
1 call to StaticThisUsageSniff::checkThisUsage()
- StaticThisUsageSniff::processTokenWithinScope in vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Scope/ StaticThisUsageSniff.php - Processes this test, when one of its tokens is encountered.
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Scope/ StaticThisUsageSniff.php, line 85
Class
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\ScopeCode
private function checkThisUsage(File $phpcsFile, $next, $end) {
$tokens = $phpcsFile->getTokens();
do {
$next = $phpcsFile->findNext([
T_VARIABLE,
T_ANON_CLASS,
], $next + 1, $end);
if ($next === false) {
continue;
}
if ($tokens[$next]['code'] === T_ANON_CLASS) {
$this->checkThisUsage($phpcsFile, $next, $tokens[$next]['scope_opener']);
$next = $tokens[$next]['scope_closer'];
continue;
}
if ($tokens[$next]['content'] !== '$this') {
continue;
}
$error = 'Usage of "$this" in static methods will cause runtime errors';
$phpcsFile->addError($error, $next, 'Found');
} while ($next !== false);
}