Skip to content
40 changes: 28 additions & 12 deletions src/DefinitionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,21 +493,37 @@ private function resolveScopedPropertyAccessExpressionNodeToFqn(Node\Expression\
} elseif ($scoped->scopeResolutionQualifier instanceof Node\QualifiedName) {
$className = $scoped->scopeResolutionQualifier->getResolvedName();
}
if ($scoped->memberName instanceof Node\Expression\Variable) {
$origName = null;
do {
if ($scoped->memberName instanceof Node\Expression\Variable) {
if ($scoped->parent instanceof Node\Expression\CallExpression) {
return null;
}
$memberName = $scoped->memberName->getName();
if (empty($memberName)) {
return null;
}
$name = (string)$className . '::$' . $memberName;
} else {
$name = (string)$className . '::' . $scoped->memberName->getText($scoped->getFileContents());
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of logic here that does not change on each loop iteration, such as the instanceof checks above and the member name. Could you save this in variables and move it out of the loop?

if ($scoped->parent instanceof Node\Expression\CallExpression) {
return null;
$name .= '()';
}
$memberName = $scoped->memberName->getName();
if (empty($memberName)) {
return null;
if ($origName === null) {
$origName = $name;
}
$name = (string)$className . '::$' . $memberName;
} else {
$name = (string)$className . '::' . $scoped->memberName->getText($scoped->getFileContents());
}
if ($scoped->parent instanceof Node\Expression\CallExpression) {
$name .= '()';
}
$definition = $this->index->getDefinition($name);
if (!!$definition) {
break;
} else {
$class = $this->index->getDefinition((string)$className);
if ($class === null || empty($class->extends)) {
return $origName;
}
$className = $class->extends[0];
}
} while (true);
return $name;
}

Expand Down