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

Breadcrumb

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

function VariableAnalysisSniff::processVariableAsStaticMember

* Process a variable that is being accessed with static syntax. * * That is, this will record the use of a variable of the form * `MyClass::$myVariable` or `self::$myVariable`. * * Can be called for any token and will return false if the variable is not * of this type. * *

Parameters

File $phpcsFile: * @param int $stackPtr * * @return bool

1 call to VariableAnalysisSniff::processVariableAsStaticMember()
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 1024

Class

VariableAnalysisSniff

Namespace

VariableAnalysis\Sniffs\CodeAnalysis

Code

protected function processVariableAsStaticMember(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $doubleColonPtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
    if ($doubleColonPtr === false || $tokens[$doubleColonPtr]['code'] !== T_DOUBLE_COLON) {
        return false;
    }
    $classNamePtr = $phpcsFile->findPrevious(Tokens::$emptyTokens, $doubleColonPtr - 1, null, true);
    $staticReferences = [
        T_STRING,
        T_SELF,
        T_PARENT,
        T_STATIC,
        T_VARIABLE,
    ];
    if ($classNamePtr === false || !in_array($tokens[$classNamePtr]['code'], $staticReferences, true)) {
        return false;
    }
    // "When calling static methods, the function call is stronger than the
    // static property operator" so look for a function call.
    $parenPointer = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true);
    if ($parenPointer !== false && $tokens[$parenPointer]['code'] === T_OPEN_PARENTHESIS) {
        return false;
    }
    return true;
}
RSS feed
Powered by Drupal