private function resolveClassLike(ClassLikeWithDependencies $clwd): void
    {
        if (isset($this->resolvedClassLikes[$clwd->fullyQualifiedName])) {
            // Already resolved.
            return;
        }
        $this->resolvedClassLikes[$clwd->fullyQualifiedName] = true;

        foreach ($clwd->dependencies as $dependencyName) {
            if (isset($this->classLikes[$dependencyName])) {
                $this->resolveClassLike($this->classLikes[$dependencyName]);
            }
        }

        if (!$this->currentClassLikeNamespace) {
            $namespaceMatches = false;
        } elseif ($this->currentClassLikeNamespace->name) {
            $namespaceMatches = $this->currentClassLikeNamespace->name->toString() === $clwd->namespace;
        } else {
            $namespaceMatches = !$clwd->namespace;
        }

        // Reduntant check to make Psalm happy.
        if ($this->currentClassLikeNamespace && $namespaceMatches) {
            $this->currentClassLikeNamespace->stmts[] = $clwd->node;
        } else {
            $name = $clwd->namespace ? new Name($clwd->namespace) : null;
            $this->currentClassLikeNamespace = new Namespace_($name, [$clwd->node]);
            $this->classLikeNamespaces[] = $this->currentClassLikeNamespace;
        }
    }