You are here

protected function VariableAnalysisSniff::checkForAssignment in Coder 8.2

Checks if the variable is being assigned to.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile:

int $stackPtr:

string $varName:

string $currScope:

Return value

bool

1 call to VariableAnalysisSniff::checkForAssignment()
VariableAnalysisSniff::processVariable in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Called to process normal member vars.

File

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

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

protected function checkForAssignment(File $phpcsFile, $stackPtr, $varName, $currScope) {
  $tokens = $phpcsFile
    ->getTokens();

  // Is the next non-whitespace an assignment?
  if (($assignPtr = $this
    ->isNextThingAnAssign($phpcsFile, $stackPtr)) === false) {
    return false;
  }

  // Plain ol' assignment. Simpl(ish).
  if (($writtenPtr = $this
    ->findWhereAssignExecuted($phpcsFile, $assignPtr)) === false) {
    $writtenPtr = $stackPtr;

    // I dunno.
  }

  // Check for the ampersand '&' after the assignment, which means this
  // variable is taken by reference.
  $refPtr = $phpcsFile
    ->findNext(T_WHITESPACE, $assignPtr + 1, null, true);
  if ($tokens[$refPtr]['code'] === T_BITWISE_AND) {
    $varInfo = $this
      ->getVariableInfo($varName, $currScope);
    $varInfo->passByReference = true;
  }
  $this
    ->markVariableAssignment($varName, $writtenPtr, $currScope);
  return true;
}