function VariableAnalysisSniff::findFunctionCallArguments in Coder 8.2
Get the arguments of a function call.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile:
int $stackPtr:
Return value
array|false
3 calls to VariableAnalysisSniff::findFunctionCallArguments()
- VariableAnalysisSniff::checkForPassByReferenceFunctionCall in coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - Check if this is a "&" function call.
- VariableAnalysisSniff::processCompact in coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - Called to process variables named in a call to compact().
- VariableAnalysisSniff::processCompactArguments in coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php - Check variables in a compact() call.
File
- coder_sniffer/
DrupalPractice/ Sniffs/ CodeAnalysis/ VariableAnalysisSniff.php, line 1152
Class
- VariableAnalysisSniff
- Checks the for undefined function variables.
Namespace
DrupalPractice\Sniffs\CodeAnalysisCode
function findFunctionCallArguments(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
// Slight hack: also allow this to find args for array constructor.
// TODO: probably should refactor into three functions: arg-finding and bracket-finding.
if ($tokens[$stackPtr]['code'] !== T_STRING && $tokens[$stackPtr]['code'] !== T_ARRAY) {
// Assume $stackPtr is something within the brackets, find our function call.
if (($stackPtr = $this
->findFunctionCall($phpcsFile, $stackPtr)) === false) {
return false;
}
}
// $stackPtr is the function name, find our brackets after it.
$openPtr = $phpcsFile
->findNext(T_WHITESPACE, $stackPtr + 1, null, true, null, true);
if ($openPtr === false || $tokens[$openPtr]['code'] !== T_OPEN_PARENTHESIS) {
return false;
}
if (isset($tokens[$openPtr]['parenthesis_closer']) === false) {
return false;
}
$closePtr = $tokens[$openPtr]['parenthesis_closer'];
$argPtrs = array();
$lastPtr = $openPtr;
$lastArgComma = $openPtr;
while (($nextPtr = $phpcsFile
->findNext(T_COMMA, $lastPtr + 1, $closePtr)) !== false) {
if ($this
->findContainingBrackets($phpcsFile, $nextPtr) === $openPtr) {
// Comma is at our level of brackets, it's an argument delimiter.
array_push($argPtrs, range($lastArgComma + 1, $nextPtr - 1));
$lastArgComma = $nextPtr;
}
$lastPtr = $nextPtr;
}
array_push($argPtrs, range($lastArgComma + 1, $closePtr - 1));
return $argPtrs;
}