public static function replaceClauses($statement, $list, array $ops)
    {
        $count = count($ops);

        // Nothing to do.
        if ($count === 0) {
            return '';
        }

        /**
         * Value to be returned.
         *
         * @var string
         */
        $ret = '';

        // If there is only one clause, `replaceClause()` should be used.
        if ($count === 1) {
            return static::replaceClause(
                $statement,
                $list,
                $ops[0][0],
                $ops[0][1]
            );
        }

        // Adding everything before first replacement.
        $ret .= static::getClause($statement, $list, $ops[0][0], -1) . ' ';

        // Doing replacements.
        foreach ($ops as $i => $clause) {
            $ret .= $clause[1] . ' ';

            // Adding everything between this and next replacement.
            if ($i + 1 !== $count) {
                $ret .= static::getClause($statement, $list, $clause[0], $ops[$i + 1][0]) . ' ';
            }
        }

        // Adding everything after the last replacement.
        $ret .= static::getClause($statement, $list, $ops[$count - 1][0], 1);

        return $ret;
    }
public static function replaceClauses($statement, $list, array $ops)
    {
        $count = count($ops);

        // Nothing to do.
        if ($count === 0) {
            return '';
        }

        /**
         * Value to be returned.
         *
         * @var string
         */
        $ret = '';

        // If there is only one clause, `replaceClause()` should be used.
        if ($count === 1) {
            return static::replaceClause(
                $statement,
                $list,
                $ops[0][0],
                $ops[0][1]
            );
        }

        // Adding everything before first replacement.
        $ret .= static::getClause($statement, $list, $ops[0][0], -1) . ' ';

        // Doing replacements.
        foreach ($ops as $i => $clause) {
            $ret .= $clause[1] . ' ';

            // Adding everything between this and next replacement.
            if ($i + 1 !== $count) {
                $ret .= static::getClause($statement, $list, $clause[0], $ops[$i + 1][0]) . ' ';
            }
        }

        // Adding everything after the last replacement.
        $ret .= static::getClause($statement, $list, $ops[$count - 1][0], 1);

        return $ret;
    }
public static function replaceClauses ( $ statement , $ list , array $ ops ) { $ count = count ( $ ops ) ; // Nothing to do. if ( $ count === 0 ) { return '' ; } /**
         * Value to be returned.
         *
         * @var string
         */ $ ret = '' ; // If there is only one clause, `replaceClause()` should be used. if ( $ count === 1 ) { return static :: replaceClause ( $ statement , $ list , $ ops [ 0 ] [ 0 ] , $ ops [ 0 ] [ 1 ] ) ; } // Adding everything before first replacement. $ ret .= static :: getClause ( $ statement , $ list , $ ops [ 0 ] [ 0 ] , - 1 ) . ' ' ; // Doing replacements. foreach ( $ ops as $ i => $ clause ) { $ ret .= $ clause [ 1 ] . ' ' ; // Adding everything between this and next replacement. if ( $ i + 1 !== $ count ) { $ ret .= static :: getClause ( $ statement , $ list , $ clause [ 0 ] , $ ops [ $ i + 1 ] [ 0 ] ) . ' ' ; } } // Adding everything after the last replacement. $ ret .= static :: getClause ( $ statement , $ list , $ ops [ $ count - 1 ] [ 0 ] , 1 ) ; return $ ret ; }
Builds a query by rebuilding the statement from the tokens list supplied
and replaces multiple clauses.

@param Statement  $statement the parsed query that has to be modified
@param TokensList $list      the list of tokens
@param array      $ops       Clauses to be replaced. Contains multiple
arrays having two values: array($old, $new).
Clauses must be sorted.

@return string
Builds a query by rebuilding the statement from the tokens list supplied and replaces multiple clauses .