Expanded class hierarchy of PHP_Token_FUNCTION
class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility {
protected $arguments;
protected $ccn;
protected $name;
protected $signature;
public function getArguments() {
if ($this->arguments !== NULL) {
return $this->arguments;
}
$this->arguments = array();
$i = $this->id + 3;
$tokens = $this->tokenStream
->tokens();
$typeHint = NULL;
while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) {
if ($tokens[$i] instanceof PHP_Token_STRING) {
$typeHint = (string) $tokens[$i];
}
else {
if ($tokens[$i] instanceof PHP_Token_VARIABLE) {
$this->arguments[(string) $tokens[$i]] = $typeHint;
$typeHint = NULL;
}
}
$i++;
}
return $this->arguments;
}
public function getName() {
if ($this->name !== NULL) {
return $this->name;
}
$tokens = $this->tokenStream
->tokens();
if ($tokens[$this->id + 2] instanceof PHP_Token_STRING) {
$this->name = (string) $tokens[$this->id + 2];
}
else {
if ($tokens[$this->id + 2] instanceof PHP_Token_AMPERSAND && $tokens[$this->id + 3] instanceof PHP_Token_STRING) {
$this->name = (string) $tokens[$this->id + 3];
}
else {
$this->name = 'anonymous function';
}
}
if ($this->name != 'anonymous function') {
for ($i = $this->id; $i; --$i) {
if ($tokens[$i] instanceof PHP_Token_NAMESPACE) {
$this->name = $tokens[$i]
->getName() . '\\' . $this->name;
break;
}
if ($tokens[$i] instanceof PHP_Token_INTERFACE) {
break;
}
}
}
return $this->name;
}
public function getCCN() {
if ($this->ccn !== NULL) {
return $this->ccn;
}
$this->ccn = 1;
$end = $this
->getEndTokenId();
$tokens = $this->tokenStream
->tokens();
for ($i = $this->id; $i <= $end; $i++) {
switch (get_class($tokens[$i])) {
case 'PHP_Token_IF':
case 'PHP_Token_ELSEIF':
case 'PHP_Token_FOR':
case 'PHP_Token_FOREACH':
case 'PHP_Token_WHILE':
case 'PHP_Token_CASE':
case 'PHP_Token_CATCH':
case 'PHP_Token_BOOLEAN_AND':
case 'PHP_Token_LOGICAL_AND':
case 'PHP_Token_BOOLEAN_OR':
case 'PHP_Token_LOGICAL_OR':
case 'PHP_Token_QUESTION_MARK':
$this->ccn++;
break;
}
}
return $this->ccn;
}
public function getSignature() {
if ($this->signature !== NULL) {
return $this->signature;
}
if ($this
->getName() == 'anonymous function') {
$this->signature = 'anonymous function';
$i = $this->id + 1;
}
else {
$this->signature = '';
$i = $this->id + 2;
}
$tokens = $this->tokenStream
->tokens();
while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) {
$this->signature .= $tokens[$i++];
}
$this->signature .= ')';
return $this->signature;
}
}