1
0
Fork 0

Support compound types when resolving FQNs

pull/166/head
Felix Becker 2016-11-19 11:45:25 +01:00
parent fb84741d55
commit 00bc8537a6
1 changed files with 21 additions and 2 deletions

View File

@ -183,8 +183,27 @@ class DefinitionResolver
}
// Get the type of the left-hand expression
$varType = $this->resolveExpressionNodeToType($node->var);
if ($varType instanceof Types\This) {
// $this is resolved to the containing class
if ($varType instanceof Types\Compound) {
// For compound types, use the first FQN we find
// (popular use case is ClassName|null)
for ($i = 0; $t = $varType->get($i); $i++) {
if (
$t instanceof Types\This
|| $t instanceof Types\Object_
|| $t instanceof Types\Static_
|| $t instanceof Types\Self_
) {
$varType = $t;
break;
}
}
}
if (
$varType instanceof Types\This
|| $varType instanceof Types\Static_
|| $varType instanceof Types\Self_
) {
// $this/static/self is resolved to the containing class
$classFqn = self::getContainingClassFqn($node);
} else if (!($varType instanceof Types\Object_) || $varType->getFqsen() === null) {
// Left-hand expression could not be resolved to a class