Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support inherited static functions #679

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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