Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractVariableSniff.php

function AbstractVariableSniff::processTokenOutsideScope

Processes the token outside the scope in the 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.:

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::processTokenOutsideScope

File

vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractVariableSniff.php, line 162

Class

AbstractVariableSniff

Namespace

PHP_CodeSniffer\Sniffs

Code

protected final function processTokenOutsideScope(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    // These variables are not member vars.
    if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
        return $this->processVariable($phpcsFile, $stackPtr);
    }
    else {
        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);
            }
        }
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal