You are here

protected function VariableAnalysisSniff::processVariableInString in Coder 8.2

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

\PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this: token was found.

int $stackPtr The position where the double quoted: string was found.

Return value

void

1 call to VariableAnalysisSniff::processVariableInString()
VariableAnalysisSniff::process in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Processes this test, when one of its tokens is encountered.

File

coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php, line 2080

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

protected function processVariableInString(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  $token = $tokens[$stackPtr];
  $runMatch = preg_match_all($this->_double_quoted_variable_regexp, $token['content'], $matches);
  if ($runMatch === 0 || $runMatch === false) {
    return;
  }
  $currScope = $this
    ->findVariableScope($phpcsFile, $stackPtr);
  foreach ($matches[1] as $varName) {
    $varName = $this
      ->normalizeVarName($varName);

    // Are we $this within a class?
    if ($this
      ->checkForThisWithinClass($phpcsFile, $stackPtr, $varName, $currScope) === true) {
      continue;
    }
    if ($this
      ->checkForSuperGlobal($phpcsFile, $stackPtr, $varName, $currScope) === true) {
      continue;
    }
    $this
      ->markVariableReadAndWarnIfUndefined($phpcsFile, $varName, $stackPtr, $currScope);
  }
}