public function visitClass(Decl $node) : Context
{
if ($node->flags & \ast\flags\CLASS_ANONYMOUS) {
$class_name = (new ContextNode($this->code_base, $this->context, $node))->getUnqualifiedNameForAnonymousClass();
} else {
$class_name = (string) $node->name;
}
assert(!empty($class_name), "Class name cannot be empty");
$alternate_id = 0;
// Hunt for the alternate of this class defined
// in this file
do {
$class_fqsen = FullyQualifiedClassName::fromStringInContext($class_name, $this->context)->withAlternateId($alternate_id++);
if (!$this->code_base->hasClassWithFQSEN($class_fqsen)) {
throw new CodeBaseException($class_fqsen, "Can't find class {$class_fqsen} - aborting");
}
$clazz = $this->code_base->getClassByFQSEN($class_fqsen);
} while ($this->context->getProjectRelativePath() != $clazz->getFileRef()->getProjectRelativePath() || $this->context->getLineNumberStart() != $clazz->getFileRef()->getLineNumberStart());
return $clazz->getContext()->withScope($clazz->getInternalScope());
}