🚀 Support variable type hinting
parent
503cc6bcff
commit
9b11614f1e
|
@ -732,10 +732,12 @@ class DefinitionResolver
|
||||||
// Use @param tag
|
// Use @param tag
|
||||||
foreach ($docBlock->getTagsByName('param') as $paramTag) {
|
foreach ($docBlock->getTagsByName('param') as $paramTag) {
|
||||||
if ($paramTag->getVariableName() === $node->name) {
|
if ($paramTag->getVariableName() === $node->name) {
|
||||||
if ($paramTag->getType() === null) {
|
$type = $paramTag->getType();
|
||||||
|
|
||||||
|
if ($type === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $paramTag->getType();
|
return $type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -759,6 +761,41 @@ class DefinitionResolver
|
||||||
}
|
}
|
||||||
return $type ?? new Types\Mixed;
|
return $type ?? new Types\Mixed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($node instanceof Node\Var_) {
|
||||||
|
$docBlock = $node->getAttribute('docBlock');
|
||||||
|
if ($docBlock !== null) {
|
||||||
|
// use @var tag
|
||||||
|
foreach($docBlock->getTagsByName('var') as $varTag) {
|
||||||
|
$type = $varTag->getType();
|
||||||
|
|
||||||
|
if($type === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($node->default !== null) {
|
||||||
|
$defaultType = $this->resolveExpressionNodeToType($node->default);
|
||||||
|
if (isset($type) && !is_a($type, get_class($defaultType))) {
|
||||||
|
$type = new Types\Compound([$type, $defaultType]);
|
||||||
|
} else {
|
||||||
|
$type = $defaultType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $type ?? new Types\Mixed;
|
||||||
|
}
|
||||||
|
|
||||||
if ($node instanceof Node\FunctionLike) {
|
if ($node instanceof Node\FunctionLike) {
|
||||||
// Functions/methods
|
// Functions/methods
|
||||||
$docBlock = $node->getAttribute('docBlock');
|
$docBlock = $node->getAttribute('docBlock');
|
||||||
|
@ -887,6 +924,6 @@ class DefinitionResolver
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (string)$node->args[0]->value->value;
|
return (string)$node->args[0]->value->value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue