function AbstractVariableSniff::processTokenWithinScope
Processes the token in the specified PHP_CodeSniffer\Files\File.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this: token was found.
int $stackPtr The position where the token was found.:
int $currScope The current scope opener token.:
Return value
void|int Optionally returns a stack pointer. The sniff will not be called again on the current file until the returned stack pointer is reached. Return `$phpcsFile->numTokens` to skip the rest of the file.
Overrides AbstractScopeSniff::processTokenWithinScope
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Sniffs/ AbstractVariableSniff.php, line 78
Class
Namespace
PHP_CodeSniffer\SniffsCode
protected final function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) {
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING || $tokens[$stackPtr]['code'] === T_HEREDOC) {
// Check to see if this string has a variable in it.
$pattern = '|(?<!\\\\)(?:\\\\{2})*\\${?[a-zA-Z0-9_]+}?|';
if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
return $this->processVariableInString($phpcsFile, $stackPtr);
}
return;
}
// If this token is nested inside a function at a deeper
// level than the current OO scope that was found, it's a normal
// variable and not a member var.
$conditions = array_reverse($tokens[$stackPtr]['conditions'], true);
$inFunction = false;
foreach ($conditions as $scope => $code) {
if (isset(Tokens::$ooScopeTokens[$code]) === true) {
break;
}
if ($code === T_FUNCTION || $code === T_CLOSURE) {
$inFunction = true;
}
}
if ($scope !== $currScope) {
// We found a closer scope to this token, so ignore
// this particular time through the sniff. We will process
// this token when this closer scope is found to avoid
// duplicate checks.
return;
}
// Just make sure this isn't a variable in a function declaration.
if ($inFunction === false && isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
foreach ($tokens[$stackPtr]['nested_parenthesis'] as $opener => $closer) {
if (isset($tokens[$opener]['parenthesis_owner']) === false) {
// Check if this is a USE statement for a closure.
$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $opener - 1, null, true);
if ($tokens[$prev]['code'] === T_USE) {
$inFunction = true;
break;
}
continue;
}
$owner = $tokens[$opener]['parenthesis_owner'];
if ($tokens[$owner]['code'] === T_FUNCTION || $tokens[$owner]['code'] === T_CLOSURE) {
$inFunction = true;
break;
}
}
}
//end if
if ($inFunction === true) {
return $this->processVariable($phpcsFile, $stackPtr);
}
else {
return $this->processMemberVar($phpcsFile, $stackPtr);
}
}