public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
    {
        $name = strtolower($node->getFirst());

        $parentNode = ParentNodeAppender::findParent($node);

        if ($parentNode instanceof ClassLike
            && $node instanceof NamedIdentifier
            && $node->getOriginalNode() === $parentNode->name
        ) {
            // The current node can either be the class like name or one of its elements, e.g. extends or implements.
            // In the first case, the node was original an Identifier.

            return null;
        }

        $useStatements = $this->nodes[(string) $namespaceName] ?? [];

        foreach ($useStatements as $use_) {
            foreach ($use_->uses as $useStatement) {
                if (!($useStatement instanceof UseUse)) {
                    continue;
                }

                if ($name === $useStatement->getAlias()->toLowerString()) {
                    if ($this->isFunctionName($node, $parentNode)) {
                        if (Use_::TYPE_FUNCTION === $use_->type) {
                            return $useStatement->name;
                        }

                        continue;
                    }

                    if ($parentNode instanceof ConstFetch && 1 === count($node->parts)) {
                        if (Use_::TYPE_CONSTANT === $use_->type) {
                            return $useStatement->name;
                        }

                        continue;
                    }

                    // Match the alias
                    return $useStatement->name;
                }

                if (null !== $useStatement->alias) {
                    continue;
                }
            }
        }

        return null;
    }
public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
    {
        $name = strtolower($node->getFirst());

        $parentNode = ParentNodeAppender::findParent($node);

        if ($parentNode instanceof ClassLike
            && $node instanceof NamedIdentifier
            && $node->getOriginalNode() === $parentNode->name
        ) {
            // The current node can either be the class like name or one of its elements, e.g. extends or implements.
            // In the first case, the node was original an Identifier.

            return null;
        }

        $useStatements = $this->nodes[(string) $namespaceName] ?? [];

        foreach ($useStatements as $use_) {
            foreach ($use_->uses as $useStatement) {
                if (!($useStatement instanceof UseUse)) {
                    continue;
                }

                if ($name === $useStatement->getAlias()->toLowerString()) {
                    if ($this->isFunctionName($node, $parentNode)) {
                        if (Use_::TYPE_FUNCTION === $use_->type) {
                            return $useStatement->name;
                        }

                        continue;
                    }

                    if ($parentNode instanceof ConstFetch && 1 === count($node->parts)) {
                        if (Use_::TYPE_CONSTANT === $use_->type) {
                            return $useStatement->name;
                        }

                        continue;
                    }

                    // Match the alias
                    return $useStatement->name;
                }

                if (null !== $useStatement->alias) {
                    continue;
                }
            }
        }

        return null;
    }
public function findStatementForNode ( ? Name $ namespaceName , Name $ node ) : ? Name { $ name = strtolower ( $ node -> getFirst ( ) ) ; $ parentNode = ParentNodeAppender :: findParent ( $ node ) ; if ( $ parentNode instanceof ClassLike && $ node instanceof NamedIdentifier && $ node -> getOriginalNode ( ) === $ parentNode -> name ) { // The current node can either be the class like name or one of its elements, e.g. extends or implements. // In the first case, the node was original an Identifier. return null ; } $ useStatements = $ this -> nodes [ ( string ) $ namespaceName ] ?? [ ] ; foreach ( $ useStatements as $ use_ ) { foreach ( $ use_ -> uses as $ useStatement ) { if ( ! ( $ useStatement instanceof UseUse ) ) { continue ; } if ( $ name === $ useStatement -> getAlias ( ) -> toLowerString ( ) ) { if ( $ this -> isFunctionName ( $ node , $ parentNode ) ) { if ( Use_ :: TYPE_FUNCTION === $ use_ -> type ) { return $ useStatement -> name ; } continue ; } if ( $ parentNode instanceof ConstFetch && 1 === count ( $ node -> parts ) ) { if ( Use_ :: TYPE_CONSTANT === $ use_ -> type ) { return $ useStatement -> name ; } continue ; } // Match the alias return $ useStatement -> name ; } if ( null !== $ useStatement -> alias ) { continue ; } } } return null ; }
Finds the statements matching the given name.

$name = 'Foo';

use X;
use Bar\Foo;
use Y;

will return the use statement for `Bar\Foo`.

@param Name|null $namespaceName
@param Name      $node

@return null|Name
Finds the statements matching the given name .