From c58407e8ad7ec67518c713164808a282e17982a8 Mon Sep 17 00:00:00 2001 From: Fuyao Zhao Date: Thu, 15 Jun 2017 05:28:49 +0800 Subject: [PATCH] Try to lookup base class member while resolveExpressionNodeToType --- src/DefinitionResolver.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/DefinitionResolver.php b/src/DefinitionResolver.php index 51c5955..bef6b9a 100644 --- a/src/DefinitionResolver.php +++ b/src/DefinitionResolver.php @@ -679,6 +679,29 @@ class DefinitionResolver return new Types\Object_(new Fqsen('\\' . $classFqn)); } return $def->type; + $memberSuffix = '->' . $expr->name; + if ($expr instanceof Node\Expr\MethodCall) { + $memberSuffix .= '()'; + } + + // Find the right class that implements the member + $implementorFqns = [$classFqn]; + while ($implementorFqn = array_shift($implementorFqns)) { + // If the member FQN exists, return it + $def = $this->index->getDefinition($implementorFqn . $memberSuffix); + if ($def) { + return $def->type; + } + // Get Definition of implementor class + $implementorDef = $this->index->getDefinition($implementorFqn); + // If it doesn't exist, return the initial guess + if ($implementorDef === null) { + break; + } + // Repeat for parent class + if ($implementorDef->extends) { + foreach ($implementorDef->extends as $extends) { + $implementorFqns[] = $extends; } } }