PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer::replaceNameOccurrences PHP Метод

replaceNameOccurrences() приватный Метод

Replace occurrences of the name of the classy element by "self" (if possible).
private replaceNameOccurrences ( Tokens $tokens, string $name, integer $startIndex, integer $endIndex )
$tokens PhpCsFixer\Tokenizer\Tokens
$name string
$startIndex integer
$endIndex integer
    private function replaceNameOccurrences(Tokens $tokens, $name, $startIndex, $endIndex)
    {
        $tokensAnalyzer = new TokensAnalyzer($tokens);
        for ($i = $startIndex; $i < $endIndex; ++$i) {
            $token = $tokens[$i];
            if ($token->isGivenKind(T_CLASS) && $tokensAnalyzer->isAnonymousClass($i) || $token->isGivenKind(T_FUNCTION) && $tokensAnalyzer->isLambda($i)) {
                $i = $tokens->getNextTokenOfKind($i, array('{'));
                $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i);
                continue;
            }
            if (!$token->equals(array(T_STRING, $name), false)) {
                continue;
            }
            $prevToken = $tokens[$tokens->getPrevMeaningfulToken($i)];
            $nextToken = $tokens[$tokens->getNextMeaningfulToken($i)];
            // skip tokens that are part of a fully qualified name
            if ($prevToken->isGivenKind(T_NS_SEPARATOR) || $nextToken->isGivenKind(T_NS_SEPARATOR)) {
                continue;
            }
            if ($prevToken->isGivenKind(array(T_INSTANCEOF, T_NEW)) || $nextToken->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM)) {
                $token->setContent('self');
            }
        }
    }