From ab5333ff74be9be933a546c59a0861617d70288e Mon Sep 17 00:00:00 2001 From: Julian Schwuchow Date: Fri, 25 Jan 2019 15:04:13 +0100 Subject: [PATCH] Added completion support to type hinted local variables. --- src/DefinitionResolver.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index adddf774..3c246ab0 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -822,8 +822,22 @@ public function resolveExpressionNodeToType($expr) } // ASSIGNMENT EXPRESSION + // first var tag will be used to resolve the type if present + // otherwise // $a = $myExpression => resolves to the type of the right-hand operand if ($expr instanceof Node\Expression\AssignmentExpression) { + $declarationNode = + ParserHelpers\tryGetPropertyDeclaration($expr) ?? + ParserHelpers\tryGetConstOrClassConstDeclaration($expr); + $declarationNode = $declarationNode ?? $expr; + + if ( + ($docBlock = $this->getDocBlock($declarationNode)) + && !empty($varTags = $docBlock->getTagsByName('var')) + && ($type = $varTags[0]->getType()) + ) { + return $type; + } return $this->resolveExpressionNodeToType($expr->rightOperand); }