src/NodeVisitor.php
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;
        }
    }
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;
        }
    }
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 ; } }
Populates the `classLikeNamespaces` property with namespaces with classes
declared in a valid order.

@param ClassLikeWithDependencies $clwd
@return void
Populates the classLikeNamespaces property with namespaces with classes declared in a valid order .