You are here

protected function VariableAnalysisSniff::checkForListAssignment in Coder 8.2

Check if this is a list language construct assignment.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile:

int $stackPtr:

string $varName:

string $currScope:

Return value

bool

1 call to VariableAnalysisSniff::checkForListAssignment()
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 1593

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

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

  // OK, are we within a list (...) construct?
  if (($openPtr = $this
    ->findContainingBrackets($phpcsFile, $stackPtr)) === false) {
    return false;
  }
  $prevPtr = $phpcsFile
    ->findPrevious(T_WHITESPACE, $openPtr - 1, null, true, null, true);
  if ($prevPtr === false || $tokens[$prevPtr]['code'] !== T_LIST) {
    return false;
  }

  // OK, we're a list (...) construct... are we being assigned to?
  $closePtr = $tokens[$openPtr]['parenthesis_closer'];
  if (($assignPtr = $this
    ->isNextThingAnAssign($phpcsFile, $closePtr)) === false) {
    return false;
  }

  // Yes, we're being assigned.
  $writtenPtr = $this
    ->findWhereAssignExecuted($phpcsFile, $assignPtr);
  $this
    ->markVariableAssignment($varName, $writtenPtr, $currScope);
  return true;
}