private function fixBackticks(Tokens $tokens, array $backtickTokens)
    {
        // Track indexes for final override
        ksort($backtickTokens);
        $openingBacktickIndex = key($backtickTokens);
        end($backtickTokens);
        $closingBacktickIndex = key($backtickTokens);

        // Strip enclosing backticks
        array_shift($backtickTokens);
        array_pop($backtickTokens);

        // Double-quoted strings are parsed differently if they contain
        // variables or not, so we need to build the new token array accordingly
        $count = \count($backtickTokens);

        $newTokens = [
            new Token([T_STRING, 'shell_exec']),
            new Token('('),
        ];
        if (1 !== $count) {
            $newTokens[] = new Token('"');
        }
        foreach ($backtickTokens as $token) {
            if (!$token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) {
                $newTokens[] = $token;

                continue;
            }
            $content = $token->getContent();
            // Escaping special chars depends on the context: too tricky
            if (Preg::match('/[`"\']/u', $content)) {
                return;
            }

            $kind = T_ENCAPSED_AND_WHITESPACE;
            if (1 === $count) {
                $content = '"'.$content.'"';
                $kind = T_CONSTANT_ENCAPSED_STRING;
            }

            $newTokens[] = new Token([$kind, $content]);
        }
        if (1 !== $count) {
            $newTokens[] = new Token('"');
        }
        $newTokens[] = new Token(')');

        $tokens->overrideRange($openingBacktickIndex, $closingBacktickIndex, $newTokens);
    }
private function fixBackticks(Tokens $tokens, array $backtickTokens)
    {
        
        ksort($backtickTokens);
        $openingBacktickIndex = key($backtickTokens);
        end($backtickTokens);
        $closingBacktickIndex = key($backtickTokens);

        
        array_shift($backtickTokens);
        array_pop($backtickTokens);

        
        
        $count = \count($backtickTokens);

        $newTokens = [
            new Token([T_STRING, 'shell_exec']),
            new Token('('),
        ];
        if (1 !== $count) {
            $newTokens[] = new Token('"');
        }
        foreach ($backtickTokens as $token) {
            if (!$token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) {
                $newTokens[] = $token;

                continue;
            }
            $content = $token->getContent();
            
            if (Preg::match('/[`"\']/u', $content)) {
                return;
            }

            $kind = T_ENCAPSED_AND_WHITESPACE;
            if (1 === $count) {
                $content = '"'.$content.'"';
                $kind = T_CONSTANT_ENCAPSED_STRING;
            }

            $newTokens[] = new Token([$kind, $content]);
        }
        if (1 !== $count) {
            $newTokens[] = new Token('"');
        }
        $newTokens[] = new Token(')');

        $tokens->overrideRange($openingBacktickIndex, $closingBacktickIndex, $newTokens);
    }
private function fixBackticks ( Tokens $ tokens , array $ backtickTokens ) { // Track indexes for final override ksort ( $ backtickTokens ) ; $ openingBacktickIndex = key ( $ backtickTokens ) ; end ( $ backtickTokens ) ; $ closingBacktickIndex = key ( $ backtickTokens ) ; // Strip enclosing backticks array_shift ( $ backtickTokens ) ; array_pop ( $ backtickTokens ) ; // Double-quoted strings are parsed differently if they contain // variables or not, so we need to build the new token array accordingly $ count = \ count ( $ backtickTokens ) ; $ newTokens = [ new Token ( [ T_STRING , 'shell_exec' ] ) , new Token ( '(' ) , ] ; if ( 1 !== $ count ) { $ newTokens [ ] = new Token ( '"' ) ; } foreach ( $ backtickTokens as $ token ) { if ( ! $ token -> isGivenKind ( T_ENCAPSED_AND_WHITESPACE ) ) { $ newTokens [ ] = $ token ; continue ; } $ content = $ token -> getContent ( ) ; // Escaping special chars depends on the context: too tricky if ( Preg :: match ( '/[`"\']/u' , $ content ) ) { return ; } $ kind = T_ENCAPSED_AND_WHITESPACE ; if ( 1 === $ count ) { $ content = '"' . $ content . '"' ; $ kind = T_CONSTANT_ENCAPSED_STRING ; } $ newTokens [ ] = new Token ( [ $ kind , $ content ] ) ; } if ( 1 !== $ count ) { $ newTokens [ ] = new Token ( '"' ) ; } $ newTokens [ ] = new Token ( ')' ) ; $ tokens -> overrideRange ( $ openingBacktickIndex , $ closingBacktickIndex , $ newTokens ) ; }
Override backtick code with corresponding double-quoted string.

@param Tokens $tokens
@param array  $backtickTokens
Override backtick code with corresponding double - quoted string .