/** * Get the return type declaration (only for PHP 7+ code) * * @return ReflectionType|null */ public function getReturnType() { $namespaceForType = $this instanceof ReflectionMethod ? $this->getDeclaringClass()->getNamespaceName() : $this->getNamespaceName(); $typeHint = (new FindTypeFromAst())->__invoke($this->node->getReturnType(), $this->getLocatedSource(), $namespaceForType); if (null === $typeHint) { return null; } return ReflectionType::createFromType($typeHint, false); }
/** * @param Node\Stmt\Function_ $node */ protected function parseFunctionNode(Node\Stmt\Function_ $node) { $parameters = []; /** @var \PhpParser\Node\Param $param */ foreach ($node->params as $param) { $parameters[] = ['name' => $param->name, 'type' => (string) $param->type, 'isReference' => $param->byRef, 'isVariadic' => $param->variadic, 'isOptional' => $param->default ? true : false]; } $this->globalFunctions[] = ['name' => $node->name, 'startLine' => $node->getLine(), 'returnType' => $node->getReturnType(), 'parameters' => $parameters, 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null]; }