src/Fixer/Basic/Psr4Fixer.php
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $isNamespaceFound = false;
        $classyIndex = 0;
        $classyName = null;

        foreach ($tokens as $index => $token) {
            if ($token->isGivenKind(T_NAMESPACE)) {
                if ($isNamespaceFound) {
                    return;
                }

                $isNamespaceFound = true;
            } elseif ($token->isClassy()) {
                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
                if ($prevToken->isGivenKind(T_NEW)) {
                    continue;
                }

                if (null !== $classyName) {
                    return;
                }

                $classyIndex = $tokens->getNextMeaningfulToken($index);
                $classyName = $tokens[$classyIndex]->getContent();
            }
        }

        if (null === $classyName) {
            return;
        }

        if ($isNamespaceFound) {
            $filename = basename(str_replace('\\', '/', $file->getRealPath()), '.php');

            if ($classyName !== $filename) {
                $tokens[$classyIndex] = new Token([T_STRING, $filename]);
            }
        } else {
            $normClass = str_replace('_', '/', $classyName);
            $filename = substr(str_replace('\\', '/', $file->getRealPath()), -\strlen($normClass) - 4, -4);

            if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
                $tokens[$classyIndex] = new Token([T_STRING, str_replace('/', '_', $filename)]);
            }
        }
    }
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
    {
        $isNamespaceFound = false;
        $classyIndex = 0;
        $classyName = null;

        foreach ($tokens as $index => $token) {
            if ($token->isGivenKind(T_NAMESPACE)) {
                if ($isNamespaceFound) {
                    return;
                }

                $isNamespaceFound = true;
            } elseif ($token->isClassy()) {
                $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
                if ($prevToken->isGivenKind(T_NEW)) {
                    continue;
                }

                if (null !== $classyName) {
                    return;
                }

                $classyIndex = $tokens->getNextMeaningfulToken($index);
                $classyName = $tokens[$classyIndex]->getContent();
            }
        }

        if (null === $classyName) {
            return;
        }

        if ($isNamespaceFound) {
            $filename = basename(str_replace('\\', '/', $file->getRealPath()), '.php');

            if ($classyName !== $filename) {
                $tokens[$classyIndex] = new Token([T_STRING, $filename]);
            }
        } else {
            $normClass = str_replace('_', '/', $classyName);
            $filename = substr(str_replace('\\', '/', $file->getRealPath()), -\strlen($normClass) - 4, -4);

            if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
                $tokens[$classyIndex] = new Token([T_STRING, str_replace('/', '_', $filename)]);
            }
        }
    }
protected function applyFix ( \ SplFileInfo $ file , Tokens $ tokens ) { $ isNamespaceFound = false ; $ classyIndex = 0 ; $ classyName = null ; foreach ( $ tokens as $ index => $ token ) { if ( $ token -> isGivenKind ( T_NAMESPACE ) ) { if ( $ isNamespaceFound ) { return ; } $ isNamespaceFound = true ; } elseif ( $ token -> isClassy ( ) ) { $ prevToken = $ tokens [ $ tokens -> getPrevMeaningfulToken ( $ index ) ] ; if ( $ prevToken -> isGivenKind ( T_NEW ) ) { continue ; } if ( null !== $ classyName ) { return ; } $ classyIndex = $ tokens -> getNextMeaningfulToken ( $ index ) ; $ classyName = $ tokens [ $ classyIndex ] -> getContent ( ) ; } } if ( null === $ classyName ) { return ; } if ( $ isNamespaceFound ) { $ filename = basename ( str_replace ( '\\' , '/' , $ file -> getRealPath ( ) ) , '.php' ) ; if ( $ classyName !== $ filename ) { $ tokens [ $ classyIndex ] = new Token ( [ T_STRING , $ filename ] ) ; } } else { $ normClass = str_replace ( '_' , '/' , $ classyName ) ; $ filename = substr ( str_replace ( '\\' , '/' , $ file -> getRealPath ( ) ) , - \ strlen ( $ normClass ) - 4 , - 4 ) ; if ( $ normClass !== $ filename && strtolower ( $ normClass ) === strtolower ( $ filename ) ) { $ tokens [ $ classyIndex ] = new Token ( [ T_STRING , str_replace ( '/' , '_' , $ filename ) ] ) ; } } }
{@inheritdoc}
{