You are here

protected function Drupal_Sniffs_Semantics_FunctionCallSniff::isFunctionCall in Coder 7.2

Checks if this is a function call.

Parameters

PHP_CodeSniffer_File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

Return value

bool

1 call to Drupal_Sniffs_Semantics_FunctionCallSniff::isFunctionCall()
Drupal_Sniffs_Semantics_FunctionCallSniff::process in coder_sniffer/Drupal/Sniffs/Semantics/FunctionCallSniff.php
Processes this test, when one of its tokens is encountered.

File

coder_sniffer/Drupal/Sniffs/Semantics/FunctionCallSniff.php, line 125

Class

Drupal_Sniffs_Semantics_FunctionCallSniff
Helper class to sniff for specific function calls.

Code

protected function isFunctionCall(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();

  // Find the next non-empty token.
  $openBracket = $phpcsFile
    ->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true);
  if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {

    // Not a function call.
    return false;
  }
  if (isset($tokens[$openBracket]['parenthesis_closer']) === false) {

    // Not a function call.
    return false;
  }

  // Find the previous non-empty token.
  $search = PHP_CodeSniffer_Tokens::$emptyTokens;
  $search[] = T_BITWISE_AND;
  $previous = $phpcsFile
    ->findPrevious($search, $stackPtr - 1, null, true);
  if ($tokens[$previous]['code'] === T_FUNCTION) {

    // It's a function definition, not a function call.
    return false;
  }
  if ($tokens[$previous]['code'] === T_OBJECT_OPERATOR) {

    // It's a method invocation, not a function call.
    return false;
  }
  if ($tokens[$previous]['code'] === T_DOUBLE_COLON) {

    // It's a static method invocation, not a function call.
    return false;
  }
  return true;
}