You are here

function VariableAnalysisSniff::markVariableDeclaration in Coder 8.2

Mark the given variable as being declared.

Parameters

string $varName:

string $scopeType:

string $typeHint:

int $stackPtr:

string $currScope:

bool $permitMatchingRedeclaration:

Return value

void

4 calls to VariableAnalysisSniff::markVariableDeclaration()
VariableAnalysisSniff::checkForCatchBlock in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Checks if we are in a catch() block.
VariableAnalysisSniff::checkForFunctionPrototype in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Checks the function prototype.
VariableAnalysisSniff::checkForGlobalDeclaration in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Check if this variable is declared globally.
VariableAnalysisSniff::checkForStaticDeclaration in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Check is this is a static variable declaration.

File

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

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

function markVariableDeclaration($varName, $scopeType, $typeHint, $stackPtr, $currScope, $permitMatchingRedeclaration = false) {
  $varInfo = $this
    ->getVariableInfo($varName, $currScope);
  if (isset($varInfo->scopeType) === true) {
    if ($permitMatchingRedeclaration === false || $varInfo->scopeType !== $scopeType) {

      // Issue redeclaration/reuse warning
      // Note: we check off scopeType not firstDeclared, this is so that
      // we catch declarations that come after implicit declarations like
      // use of a variable as a local.
      $this->currentFile
        ->addWarning("Redeclaration of %s %s as %s.", $stackPtr, 'VariableRedeclaration', array(
        VariableInfo::$scopeTypeDescriptions[$varInfo->scopeType],
        "\${$varName}",
        VariableInfo::$scopeTypeDescriptions[$scopeType],
      ));
    }
  }
  $varInfo->scopeType = $scopeType;
  if (isset($typeHint) === true) {
    $varInfo->typeHint = $typeHint;
  }
  if (isset($varInfo->firstDeclared) === true && $varInfo->firstDeclared <= $stackPtr) {
    return;
  }

  // When a global variable is declared it also means we can consider it as
  // being initialized.
  if ($scopeType === 'global') {
    $varInfo->firstInitialized = $stackPtr;
  }
  $varInfo->firstDeclared = $stackPtr;
}