private static function rewriteQuery(
        $query,
        array $placeholderPositions,
        $placeholderLength,
        array $newPlaceholders
    ) {
        // The position gap produced by the rewrite.
        $positionGap = 0;

        // Generates new placeholders and his length.
        $placeholders = implode(', ', $newPlaceholders);
        $placeholdersLength = strlen($placeholders);

        // Iterate placeholder positions to rewrite each one.
        foreach ($placeholderPositions as $placeholderPosition) {

            // Rewrite the query.
            $query = substr($query, 0, $placeholderPosition + $positionGap).
                $placeholders.
                substr($query, $placeholderPosition + $positionGap + $placeholderLength);

            // Increase the position gap.
            $positionGap += $placeholdersLength - $placeholderLength;
        }

        return $query;
    }