You are here

function VariableAnalysisSniff::isVariableUndefined in Coder 8.2

Checks if the given variable is undefined.

Parameters

string $varName:

int $stackPtr:

string $currScope:

Return value

bool

2 calls to VariableAnalysisSniff::isVariableUndefined()
VariableAnalysisSniff::checkForFunctionPrototype in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Checks the function prototype.
VariableAnalysisSniff::markVariableReadAndWarnIfUndefined in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Marks a variable as read and throws a PHPCS warning if it is undefined.

File

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

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

function isVariableUndefined($varName, $stackPtr, $currScope) {
  $varInfo = $this
    ->getVariableInfo($varName, $currScope, false);
  if (isset($varInfo->firstDeclared) === true && $varInfo->firstDeclared <= $stackPtr) {

    // TODO: do we want to check scopeType here?
    return false;
  }
  if (isset($varInfo->firstInitialized) === true && $varInfo->firstInitialized <= $stackPtr) {
    return false;
  }
  return true;
}