Skip to content

Support PHP7.1 nullable types #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/DefinitionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,11 +720,21 @@ private static function resolveClassNameToType(Node $class): Type
* If it is unknown, will be Types\Mixed.
* Returns null if the node does not have a type.
*
* @param Node $node
* @param Node|string $node
* @return \phpDocumentor\Reflection\Type|null
*/
public function getTypeFromNode(Node $node)
public function getTypeFromNode($node)
{
if (is_string($node)) {
// Resolve a string like "bool" to a type object
return $this->typeResolver->resolve($node);
}
if ($node instanceof Node\Name) {
return new Types\Object_(new Fqsen('\\' . (string)$node));
}
if ($node instanceof Node\NullableType) {
return new Types\Compound([new Types\Null_, $this->getTypeFromNode($node->type)]);
}
if ($node instanceof Node\Param) {
// Parameters
$docBlock = $node->getAttribute('parentNode')->getAttribute('docBlock');
Expand All @@ -742,12 +752,7 @@ public function getTypeFromNode(Node $node)
$type = null;
if ($node->type !== null) {
// Use PHP7 return type hint
if (is_string($node->type)) {
// Resolve a string like "bool" to a type object
$type = $this->typeResolver->resolve($node->type);
} else {
$type = new Types\Object_(new Fqsen('\\' . (string)$node->type));
}
return $this->getTypeFromNode($node->type);
}
if ($node->default !== null) {
$defaultType = $this->resolveExpressionNodeToType($node->default);
Expand All @@ -771,12 +776,7 @@ public function getTypeFromNode(Node $node)
return $returnTags[0]->getType();
}
if ($node->returnType !== null) {
// Use PHP7 return type hint
if (is_string($node->returnType)) {
// Resolve a string like "bool" to a type object
return $this->typeResolver->resolve($node->returnType);
}
return new Types\Object_(new Fqsen('\\' . (string)$node->returnType));
return $this->getTypeFromNode($node->returnType);
}
// Unknown return type
return new Types\Mixed;
Expand Down