protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $useDeclarations = (new NamespaceUsesAnalyzer())->getDeclarationsFromTokens($tokens);

        if (0 === \count($useDeclarations)) {
            return;
        }

        foreach ((new NamespacesAnalyzer())->getDeclarations($tokens) as $namespace) {
            $currentNamespaceUseDeclarations = array_filter(
                $useDeclarations,
                function (NamespaceUseAnalysis $useDeclaration) use ($namespace) {
                    return
                        $useDeclaration->getStartIndex() >= $namespace->getScopeStartIndex()
                        && $useDeclaration->getEndIndex() <= $namespace->getScopeEndIndex()
                    ;
                }
            );

            $usagesSearchIgnoredIndexes = [];

            foreach ($currentNamespaceUseDeclarations as $useDeclaration) {
                $usagesSearchIgnoredIndexes[$useDeclaration->getStartIndex()] = $useDeclaration->getEndIndex();
            }

            foreach ($currentNamespaceUseDeclarations as $useDeclaration) {
                if (!$this->importIsUsed($tokens, $namespace, $usagesSearchIgnoredIndexes, $useDeclaration->getShortName())) {
                    $this->removeUseDeclaration($tokens, $useDeclaration);
                }
            }

            $this->removeUsesInSameNamespace($tokens, $currentNamespaceUseDeclarations, $namespace);
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $useDeclarations = (new NamespaceUsesAnalyzer())->getDeclarationsFromTokens($tokens);

        if (0 === \count($useDeclarations)) {
            return;
        }

        foreach ((new NamespacesAnalyzer())->getDeclarations($tokens) as $namespace) {
            $currentNamespaceUseDeclarations = array_filter(
                $useDeclarations,
                function (NamespaceUseAnalysis $useDeclaration) use ($namespace) {
                    return
                        $useDeclaration->getStartIndex() >= $namespace->getScopeStartIndex()
                        && $useDeclaration->getEndIndex() <= $namespace->getScopeEndIndex()
                    ;
                }
            );

            $usagesSearchIgnoredIndexes = [];

            foreach ($currentNamespaceUseDeclarations as $useDeclaration) {
                $usagesSearchIgnoredIndexes[$useDeclaration->getStartIndex()] = $useDeclaration->getEndIndex();
            }

            foreach ($currentNamespaceUseDeclarations as $useDeclaration) {
                if (!$this->importIsUsed($tokens, $namespace, $usagesSearchIgnoredIndexes, $useDeclaration->getShortName())) {
                    $this->removeUseDeclaration($tokens, $useDeclaration);
                }
            }

            $this->removeUsesInSameNamespace($tokens, $currentNamespaceUseDeclarations, $namespace);
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { $ useDeclarations = ( new NamespaceUsesAnalyzer ( ) ) -> getDeclarationsFromTokens ( $ tokens ) ; if ( 0 === \ count ( $ useDeclarations ) ) { return ; } foreach ( ( new NamespacesAnalyzer ( ) ) -> getDeclarations ( $ tokens ) as $ namespace ) { $ currentNamespaceUseDeclarations = array_filter ( $ useDeclarations , function ( NamespaceUseAnalysis $ useDeclaration ) use ( $ namespace ) { return $ useDeclaration -> getStartIndex ( ) >= $ namespace -> getScopeStartIndex ( ) && $ useDeclaration -> getEndIndex ( ) <= $ namespace -> getScopeEndIndex ( ) ; } ) ; $ usagesSearchIgnoredIndexes = [ ] ; foreach ( $ currentNamespaceUseDeclarations as $ useDeclaration ) { $ usagesSearchIgnoredIndexes [ $ useDeclaration -> getStartIndex ( ) ] = $ useDeclaration -> getEndIndex ( ) ; } foreach ( $ currentNamespaceUseDeclarations as $ useDeclaration ) { if ( ! $ this -> importIsUsed ( $ tokens , $ namespace , $ usagesSearchIgnoredIndexes , $ useDeclaration -> getShortName ( ) ) ) { $ this -> removeUseDeclaration ( $ tokens , $ useDeclaration ) ; } } $ this -> removeUsesInSameNamespace ( $ tokens , $ currentNamespaceUseDeclarations , $ namespace ) ; } }
{@inheritdoc}
{