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

Breadcrumb

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

function VariableAnalysisSniff::processVariableInString

* Called to process variables found in double quoted strings. * * Note that there may be more than one variable in the string, which will * result only in one call for the string. * *

Parameters

File $phpcsFile The PHP_CodeSniffer file where this token was found.: * @param int $stackPtr The position where the double quoted string was found. * * @return void

1 call to VariableAnalysisSniff::processVariableInString()
VariableAnalysisSniff::process in vendor/sirbrillig/phpcs-variable-analysis/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
* Scan and process a token. * * This is the main processing function of the sniff. Will run on every token * for which `register()` returns true. * *

File

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

Class

VariableAnalysisSniff

Namespace

VariableAnalysis\Sniffs\CodeAnalysis

Code

protected function processVariableInString(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $token = $tokens[$stackPtr];
    $regexp = Constants::getDoubleQuotedVarRegexp();
    if (!empty($regexp) && !preg_match_all($regexp, $token['content'], $matches)) {
        Helpers::debug('processVariableInString: no variables found', $token);
        return;
    }
    Helpers::debug('examining token for variable in string', $token);
    if (empty($matches)) {
        Helpers::debug('processVariableInString: no variables found after search', $token);
        return;
    }
    foreach ($matches[1] as $varName) {
        $varName = Helpers::normalizeVarName($varName);
        // Are we $this within a class?
        if ($this->processVariableAsThisWithinClass($phpcsFile, $stackPtr, $varName)) {
            continue;
        }
        if ($this->processVariableAsSuperGlobal($varName)) {
            continue;
        }
        // Are we a numeric variable used for constructs like preg_replace?
        if (Helpers::isVariableANumericVariable($varName)) {
            continue;
        }
        $currScope = Helpers::findVariableScope($phpcsFile, $stackPtr, $varName);
        if ($currScope === null) {
            continue;
        }
        $this->markVariableReadAndWarnIfUndefined($phpcsFile, $varName, $stackPtr, $currScope);
    }
}

API Navigation

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