src/Fixer/LanguageConstruct/FunctionToConstantFixer.php
private function getReplaceCandidate(Tokens $tokens, $index)
    {
        // test if we are at a function all
        if (!$tokens[$index]->isGivenKind(T_STRING)) {
            return null;
        }

        $braceOpenIndex = $tokens->getNextMeaningfulToken($index);
        if (!$tokens[$braceOpenIndex]->equals('(')) {
            return null;
        }

        // test if function call without parameters
        $braceCloseIndex = $tokens->getNextMeaningfulToken($braceOpenIndex);
        if (!$tokens[$braceCloseIndex]->equals(')')) {
            return null;
        }

        $functionNamePrefix = $tokens->getPrevMeaningfulToken($index);
        if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, CT::T_RETURN_REF])) {
            return null;
        }

        if ($tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)) {
            // skip if the call is to a constructor or to a function in a namespace other than the default
            $prevIndex = $tokens->getPrevMeaningfulToken($functionNamePrefix);
            if ($tokens[$prevIndex]->isGivenKind([T_STRING, T_NEW])) {
                return null;
            }
        }

        // test if the function call is to a native PHP function
        $lowerContent = strtolower($tokens[$index]->getContent());
        if (!\array_key_exists($lowerContent, $this->functionsFixMap)) {
            return null;
        }

        $clones = [];
        foreach ($this->functionsFixMap[$lowerContent] as $token) {
            $clones[] = clone $token;
        }

        return [
            $braceOpenIndex,
            $braceCloseIndex,
            $clones,
        ];
    }
private function getReplaceCandidate(Tokens $tokens, $index)
    {
        // test if we are at a function all
        if (!$tokens[$index]->isGivenKind(T_STRING)) {
            return null;
        }

        $braceOpenIndex = $tokens->getNextMeaningfulToken($index);
        if (!$tokens[$braceOpenIndex]->equals('(')) {
            return null;
        }

        // test if function call without parameters
        $braceCloseIndex = $tokens->getNextMeaningfulToken($braceOpenIndex);
        if (!$tokens[$braceCloseIndex]->equals(')')) {
            return null;
        }

        $functionNamePrefix = $tokens->getPrevMeaningfulToken($index);
        if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, CT::T_RETURN_REF])) {
            return null;
        }

        if ($tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)) {
            // skip if the call is to a constructor or to a function in a namespace other than the default
            $prevIndex = $tokens->getPrevMeaningfulToken($functionNamePrefix);
            if ($tokens[$prevIndex]->isGivenKind([T_STRING, T_NEW])) {
                return null;
            }
        }

        // test if the function call is to a native PHP function
        $lowerContent = strtolower($tokens[$index]->getContent());
        if (!\array_key_exists($lowerContent, $this->functionsFixMap)) {
            return null;
        }

        $clones = [];
        foreach ($this->functionsFixMap[$lowerContent] as $token) {
            $clones[] = clone $token;
        }

        return [
            $braceOpenIndex,
            $braceCloseIndex,
            $clones,
        ];
    }
private function getReplaceCandidate ( Tokens $ tokens , $ index ) { // test if we are at a function all if ( ! $ tokens [ $ index ] -> isGivenKind ( T_STRING ) ) { return null ; } $ braceOpenIndex = $ tokens -> getNextMeaningfulToken ( $ index ) ; if ( ! $ tokens [ $ braceOpenIndex ] -> equals ( '(' ) ) { return null ; } // test if function call without parameters $ braceCloseIndex = $ tokens -> getNextMeaningfulToken ( $ braceOpenIndex ) ; if ( ! $ tokens [ $ braceCloseIndex ] -> equals ( ')' ) ) { return null ; } $ functionNamePrefix = $ tokens -> getPrevMeaningfulToken ( $ index ) ; if ( $ tokens [ $ functionNamePrefix ] -> isGivenKind ( [ T_DOUBLE_COLON , T_NEW , T_OBJECT_OPERATOR , T_FUNCTION , CT :: T_RETURN_REF ] ) ) { return null ; } if ( $ tokens [ $ functionNamePrefix ] -> isGivenKind ( T_NS_SEPARATOR ) ) { // skip if the call is to a constructor or to a function in a namespace other than the default $ prevIndex = $ tokens -> getPrevMeaningfulToken ( $ functionNamePrefix ) ; if ( $ tokens [ $ prevIndex ] -> isGivenKind ( [ T_STRING , T_NEW ] ) ) { return null ; } } // test if the function call is to a native PHP function $ lowerContent = strtolower ( $ tokens [ $ index ] -> getContent ( ) ) ; if ( ! \ array_key_exists ( $ lowerContent , $ this -> functionsFixMap ) ) { return null ; } $ clones = [ ] ; foreach ( $ this -> functionsFixMap [ $ lowerContent ] as $ token ) { $ clones [ ] = clone $ token ; } return [ $ braceOpenIndex , $ braceCloseIndex , $ clones , ] ; }
@param Tokens $tokens
@param int    $index

@return null|array
@param Tokens $tokens @param int $index