1
0
Fork 0

Switched to a generator when traversing parents

pull/247/head
Ivan Bozhanov 2017-01-21 17:48:15 +02:00
parent 60153923cb
commit 7b4d0d1c60
1 changed files with 16 additions and 15 deletions

View File

@ -479,14 +479,12 @@ class DefinitionResolver
} else { } else {
$classFqn = substr((string)$t->getFqsen(), 1); $classFqn = substr((string)$t->getFqsen(), 1);
} }
$extended = $this->expandParentFqns([$classFqn]); foreach ($this->getParentsDefinition($classFqn) as $parent) {
foreach ($extended as $f) { $fqn = $parent->fqn . '->' . $expr->name;
$fqn = $f . '->' . $expr->name;
if ($expr instanceof Node\Expr\MethodCall) { if ($expr instanceof Node\Expr\MethodCall) {
$fqn .= '()'; $fqn .= '()';
} }
$def = $this->index->getDefinition($fqn); if ($def = $this->index->getDefinition($fqn)) {
if ($def !== null) {
if ($def->type instanceof Types\This || $def->type instanceof Types\Self_) { if ($def->type instanceof Types\This || $def->type instanceof Types\Self_) {
return $this->resolveExpressionNodeToType($expr->var); return $this->resolveExpressionNodeToType($expr->var);
} }
@ -660,21 +658,24 @@ class DefinitionResolver
/** /**
* Adds the FQNs of all parent classes to an array of FQNs of classes * Adds the FQNs of all parent classes to an array of FQNs of classes
* *
* @param string[] $fqns * @param string $fqns
* @return string[] * @return Definition[]
*/ */
private function expandParentFqns(array $fqns): array private function getParentsDefinition(string $fqn)
{ {
$expanded = $fqns; $def = $this->index->getDefinition($fqn);
foreach ($fqns as $fqn) { while ($def) {
$def = $this->index->getDefinition($fqn); yield $def;
if ($def && $def->extends) { if ($def->extends) {
foreach ($this->expandParentFqns($def->extends) as $parent) { foreach ($def->extends as $parent) {
$expanded[] = $parent; if (($tmp = $this->index->getDefinition($parent)) && $tmp->canBeInstantiated) {
$def = $tmp;
continue;
}
} }
} }
break;
} }
return $expanded;
} }
/** /**