prepare support for multi-types [ref #97]

This commit is contained in:
TomasVotruba 2017-10-25 12:12:01 +02:00
parent 46e366db84
commit 7f05c600f7
3 changed files with 11 additions and 6 deletions

View File

@ -45,16 +45,16 @@ final class AssignTypeResolver implements PerNodeTypeResolverInterface, NodeType
return [];
}
$variableType = $this->resolveTypeForRightSide($assignNode);
$variableTypes = $this->resolveTypeForRightSide($assignNode);
if ($variableType) {
if ($variableTypes) {
/** @var Variable $variableNode */
$variableNode = $assignNode->var;
$variableName = $variableNode->name;
$this->typeContext->addVariableWithTypes($variableName, $variableType);
$this->typeContext->addVariableWithTypes($variableName, $variableTypes);
}
return [$variableType];
return [$variableTypes];
}
public function setNodeTypeResolver(NodeTypeResolver $nodeTypeResolver): void

View File

@ -74,7 +74,7 @@ final class ParamTypeResolver implements PerNodeTypeResolverInterface, NodeTypeR
// resolve param type from docblock
$paramType = $this->docBlockAnalyzer->getParamTypeFor($classMethod, $variableName);
if ($paramType === null) {
return null;
return [];
}
// resolve to FQN

View File

@ -92,7 +92,12 @@ final class TypeContext
$functionReflection = $this->getFunctionReflection($functionLikeNode);
if ($functionReflection) {
foreach ($functionReflection->getParameters() as $parameterReflection) {
$this->variableTypes[$parameterReflection->getName()] = (string) $parameterReflection->getType();
$type = (string) $parameterReflection->getType();
if (! $type) {
continue;
}
$this->variableTypes[$parameterReflection->getName()] = [$type];
}
}
}