You are here

function VariableAnalysisSniff::findWhereAssignExecuted in Coder 8.2

Find the end of the assignment.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile:

int $stackPtr:

Return value

int

2 calls to VariableAnalysisSniff::findWhereAssignExecuted()
VariableAnalysisSniff::checkForAssignment in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Checks if the variable is being assigned to.
VariableAnalysisSniff::checkForListAssignment in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Check if this is a list language construct assignment.

File

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

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

function findWhereAssignExecuted(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();

  // Write should be recorded at the next statement to ensure we treat
  // the assign as happening after the RHS execution.
  // eg: $var = $var + 1; -> RHS could still be undef.
  // However, if we're within a bracketed expression,
  // eg: echo (($var = 12) && ($var == 12));
  // we take place at the closing bracket, if that's first.
  $semicolonPtr = $phpcsFile
    ->findNext(T_SEMICOLON, $stackPtr + 1, null, false, null, true);
  $closePtr = false;
  if (($openPtr = $this
    ->findContainingBrackets($phpcsFile, $stackPtr)) !== false) {
    if (isset($tokens[$openPtr]['parenthesis_closer']) === true) {
      $closePtr = $tokens[$openPtr]['parenthesis_closer'];
    }
  }
  if ($semicolonPtr === false) {
    if ($closePtr === false) {

      // TODO: panic.
      return $stackPtr;
    }
    return $closePtr;
  }
  if ($closePtr !== false && $closePtr < $semicolonPtr) {
    return $closePtr;
  }
  return $semicolonPtr;
}