public function getMethodParameters($stackPtr)
{
if ($this->_tokens[$stackPtr]['code'] !== T_FUNCTION) {
throw new PHP_CodeSniffer_Exception('$stackPtr must be of type T_FUNCTION');
}
$opener = $this->_tokens[$stackPtr]['parenthesis_opener'];
$closer = $this->_tokens[$stackPtr]['parenthesis_closer'];
$vars = array();
$currVar = null;
$defaultStart = null;
$paramCount = 0;
$passByReference = false;
$variableLength = false;
$typeHint = '';
for ($i = $opener + 1; $i <= $closer; $i++) {
// Check to see if this token has a parenthesis or bracket opener. If it does
// it's likely to be an array which might have arguments in it. This
// could cause problems in our parsing below, so lets just skip to the
// end of it.
if (isset($this->_tokens[$i]['parenthesis_opener']) === true) {
// Don't do this if it's the close parenthesis for the method.
if ($i !== $this->_tokens[$i]['parenthesis_closer']) {
$i = $this->_tokens[$i]['parenthesis_closer'] + 1;
}
}
if (isset($this->_tokens[$i]['bracket_opener']) === true) {
// Don't do this if it's the close parenthesis for the method.
if ($i !== $this->_tokens[$i]['bracket_closer']) {
$i = $this->_tokens[$i]['bracket_closer'] + 1;
}
}
switch ($this->_tokens[$i]['code']) {
case T_BITWISE_AND:
$passByReference = true;
break;
case T_VARIABLE:
$currVar = $i;
break;
case T_ELLIPSIS:
$variableLength = true;
break;
case T_ARRAY_HINT:
case T_CALLABLE:
$typeHint = $this->_tokens[$i]['content'];
break;
case T_STRING:
// This is a string, so it may be a type hint, but it could
// also be a constant used as a default value.
$prevComma = false;
for ($t = $i; $t >= $opener; $t--) {
if ($this->_tokens[$t]['code'] === T_COMMA) {
$prevComma = $t;
break;
}
}
if ($prevComma !== false) {
$nextEquals = false;
for ($t = $prevComma; $t < $i; $t++) {
if ($this->_tokens[$t]['code'] === T_EQUAL) {
$nextEquals = $t;
break;
}
}
if ($nextEquals !== false) {
break;
}
}
if ($defaultStart === null) {
$typeHint .= $this->_tokens[$i]['content'];
}
break;
case T_NS_SEPARATOR:
// Part of a type hint or default value.
if ($defaultStart === null) {
$typeHint .= $this->_tokens[$i]['content'];
}
break;
case T_CLOSE_PARENTHESIS:
case T_COMMA:
// If it's null, then there must be no parameters for this
// method.
if ($currVar === null) {
continue;
}
$vars[$paramCount] = array();
$vars[$paramCount]['name'] = $this->_tokens[$currVar]['content'];
if ($defaultStart !== null) {
$vars[$paramCount]['default'] = $this->getTokensAsString($defaultStart, $i - $defaultStart);
}
$vars[$paramCount]['pass_by_reference'] = $passByReference;
$vars[$paramCount]['variable_length'] = $variableLength;
$vars[$paramCount]['type_hint'] = $typeHint;
// Reset the vars, as we are about to process the next parameter.
$defaultStart = null;
$passByReference = false;
$variableLength = false;
$typeHint = '';
$paramCount++;
break;
case T_EQUAL:
$defaultStart = $i + 1;
break;
}
//end switch
}
//end for
return $vars;
}