You are here

function VariableAnalysisSniff::findFunctionPrototype in Coder 8.2

Returns the function declaration pointer.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile:

int $stackPtr:

Return value

int|false

1 call to VariableAnalysisSniff::findFunctionPrototype()
VariableAnalysisSniff::findVariableScope in coder_sniffer/DrupalPractice/Sniffs/CodeAnalysis/VariableAnalysisSniff.php
Find the scope the given pointer is in.

File

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

Class

VariableAnalysisSniff
Checks the for undefined function variables.

Namespace

DrupalPractice\Sniffs\CodeAnalysis

Code

function findFunctionPrototype(File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  if (($openPtr = $this
    ->findContainingBrackets($phpcsFile, $stackPtr)) === false) {
    return false;
  }

  // Function names are T_STRING, and return-by-reference is T_BITWISE_AND,
  // so we look backwards from the opening bracket for the first thing that
  // isn't a function name, reference sigil or whitespace and check if
  // it's a function keyword.
  $functionPtr = $phpcsFile
    ->findPrevious(array(
    T_STRING,
    T_WHITESPACE,
    T_BITWISE_AND,
  ), $openPtr - 1, null, true, null, true);
  if ($functionPtr !== false && $tokens[$functionPtr]['code'] === T_FUNCTION) {
    return $functionPtr;
  }
  return false;
}