private function parseFunctionDeclaration()
{
$this->consumeComments();
// Next token must be the function identifier
$functionName = $this->parseFunctionName();
$function = $this->builder->buildFunction($functionName);
$function->setCompilationUnit($this->compilationUnit);
$function->setId($this->idBuilder->forFunction($function));
$this->parseCallableDeclaration($function);
// First check for an existing namespace
if ($this->namespaceName !== null) {
$packageName = $this->namespaceName;
} elseif ($this->packageName !== Builder::DEFAULT_NAMESPACE) {
$packageName = $this->packageName;
} else {
$packageName = $this->globalPackageName;
}
$this->builder->buildNamespace($packageName)->addFunction($function);
// Store function in source file, because we need them during the file's
// __wakeup() phase for function declarations within another function or
// method declaration.
$this->compilationUnit->addChild($function);
return $function;
}