1
0
Fork 0

Handle more cases in DefinitionResolver

pull/155/head
Felix Becker 2016-11-17 22:56:57 +01:00
parent 13e42cc7d2
commit ba47584910
1 changed files with 38 additions and 9 deletions

View File

@ -256,7 +256,10 @@ class DefinitionResolver
return new Types\Mixed; return new Types\Mixed;
} }
$fqn = (string)($expr->getAttribute('namespacedName') ?? $expr->name); $fqn = (string)($expr->getAttribute('namespacedName') ?? $expr->name);
return $this->project->getDefinition($fqn)->type; $def = $this->project->getDefinition($fqn);
if ($def !== null) {
return $def->type;
}
} }
if ($expr instanceof Node\Expr\ConstFetch) { if ($expr instanceof Node\Expr\ConstFetch) {
if (strtolower((string)$expr->name) === 'true' || strtolower((string)$expr->name) === 'false') { if (strtolower((string)$expr->name) === 'true' || strtolower((string)$expr->name) === 'false') {
@ -264,7 +267,10 @@ class DefinitionResolver
} }
// Resolve constant // Resolve constant
$fqn = (string)($expr->getAttribute('namespacedName') ?? $expr->name); $fqn = (string)($expr->getAttribute('namespacedName') ?? $expr->name);
return $this->project->getDefinition($fqn)->type; $def = $this->project->getDefinition($fqn);
if ($def !== null) {
return $def->type;
}
} }
if ($expr instanceof Node\Expr\MethodCall) { if ($expr instanceof Node\Expr\MethodCall) {
// Resolve object // Resolve object
@ -274,7 +280,10 @@ class DefinitionResolver
return new Types\Mixed; return new Types\Mixed;
} }
$fqn = (string)$objType->getFqsen() . '::' . $expr->name . '()'; $fqn = (string)$objType->getFqsen() . '::' . $expr->name . '()';
return $this->project->getDefinition($fqn)->type; $def = $this->project->getDefinition($fqn);
if ($def !== null) {
return $def->type;
}
} }
if ($expr instanceof Node\Expr\PropertyFetch) { if ($expr instanceof Node\Expr\PropertyFetch) {
// Resolve object // Resolve object
@ -284,8 +293,10 @@ class DefinitionResolver
return new Types\Mixed; return new Types\Mixed;
} }
$fqn = (string)$objType->getFqsen() . '::' . $expr->name; $fqn = (string)$objType->getFqsen() . '::' . $expr->name;
return $this->project->getDefinition($fqn)->type; $def = $this->project->getDefinition($fqn);
} if ($def !== null) {
return $def->type; }
}
if ($expr instanceof Node\Expr\StaticCall) { if ($expr instanceof Node\Expr\StaticCall) {
if ($expr->class instanceof Node\Expr || $expr->name instanceof Node\Expr) { if ($expr->class instanceof Node\Expr || $expr->name instanceof Node\Expr) {
// Need the FQN // Need the FQN
@ -306,12 +317,30 @@ class DefinitionResolver
} }
if ($expr->class instanceof Node\Stmt\Class_) { if ($expr->class instanceof Node\Stmt\Class_) {
// Anonymous class // Anonymous class
return new Types\Object;
}
if ((string)$expr->class === 'self') {
return new Types\Object_; return new Types\Object_;
} }
return new Types\Object_(new Fqsen('\\' . (string)$expr->class)); $class = (string)$expr->class;
if ($class === 'static') {
return new Types\Static_;
}
if ($class === 'self' || $class === 'parent') {
$classNode = getClosestNode($expr, Node\Stmt\Class_::class);
if ($class === 'parent') {
if ($classNode === null || $classNode->extends === null) {
return new Types\Object_;
}
// parent is resolved to the parent class
$classFqn = (string)$classNode->extends;
} else {
if ($classNode === null) {
return new Types\Self_;
}
// self is resolved to the containing class
$classFqn = (string)$classNode->namespacedName;
}
return new Types\Object_(new Fqsen('\\' . $classFqn));
}
return new Types\Object_(new Fqsen('\\' . $class));
} }
if ($expr instanceof Node\Expr\Clone_ || $expr instanceof Node\Expr\Assign) { if ($expr instanceof Node\Expr\Clone_ || $expr instanceof Node\Expr\Assign) {
return $this->resolveExpression($expr->expr); return $this->resolveExpression($expr->expr);