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

Breadcrumb

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

function VariableAnalysisSniff::processVariableAsGlobalDeclaration

* Process a variable being defined (imported, really) with the `global` keyword. * * Can be called for any token and will return false if the variable is not * of this type. * *

Parameters

File $phpcsFile: * @param int $stackPtr * @param string $varName * @param int $currScope * * @return bool

1 call to VariableAnalysisSniff::processVariableAsGlobalDeclaration()
VariableAnalysisSniff::processVariable in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Process a normal variable in the code. * * Most importantly, this function determines if the variable use is a "read" * (using the variable for something) or a "write" (an assignment) or, * sometimes, both at once. * …

File

vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php, line 1292

Class

VariableAnalysisSniff

Namespace

VariableAnalysis\Sniffs\CodeAnalysis

Code

protected function processVariableAsGlobalDeclaration(File $phpcsFile, $stackPtr, $varName, $currScope) {
    $tokens = $phpcsFile->getTokens();
    // Are we a global declaration?
    // Search backwards for first token that isn't whitespace/comment, comma or variable.
    $ignore = Tokens::$emptyTokens;
    $ignore[T_VARIABLE] = T_VARIABLE;
    $ignore[T_COMMA] = T_COMMA;
    $globalPtr = $phpcsFile->findPrevious($ignore, $stackPtr - 1, null, true, null, true);
    if ($globalPtr === false || $tokens[$globalPtr]['code'] !== T_GLOBAL) {
        return false;
    }
    // It's a global declaration.
    $this->markVariableDeclaration($varName, ScopeType::GLOBALSCOPE, null, $stackPtr, $currScope);
    return true;
}
RSS feed
Powered by Drupal