protected function FunctionCall::isFunctionCall in Coder 8.3
Same name and namespace in other branches
- 8.2 coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php \Drupal\Sniffs\Semantics\FunctionCall::isFunctionCall()
- 8.3.x coder_sniffer/Drupal/Sniffs/Semantics/FunctionCall.php \Drupal\Sniffs\Semantics\FunctionCall::isFunctionCall()
Checks if this is a function call.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
bool
3 calls to FunctionCall::isFunctionCall()
- FunctionCall::process in coder_sniffer/
Drupal/ Sniffs/ Semantics/ FunctionCall.php - Processes this test, when one of its tokens is encountered.
- GlobalFunctionSniff::process in coder_sniffer/
DrupalPractice/ Sniffs/ Objects/ GlobalFunctionSniff.php - Processes this test, when one of its tokens is encountered.
- ThemeSniff::process in coder_sniffer/
DrupalPractice/ Sniffs/ FunctionCalls/ ThemeSniff.php - Processes this function call.
File
- coder_sniffer/
Drupal/ Sniffs/ Semantics/ FunctionCall.php, line 127
Class
- FunctionCall
- Helper class to sniff for specific function calls.
Namespace
Drupal\Sniffs\SemanticsCode
protected function isFunctionCall(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
// Find the next non-empty token.
$openBracket = $phpcsFile
->findNext(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 = 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 && $this->includeMethodCalls === false) {
// It's a method invocation, not a function call.
return false;
}
if ($tokens[$previous]['code'] === T_DOUBLE_COLON && $this->includeMethodCalls === false) {
// It's a static method invocation, not a function call.
return false;
}
return true;
}