protected function mergeOrReplaceQuery($query)
    {
        if (is_array($query)) {
            return array_merge($this->query, $query);
        }

        if (!is_string($query)) {
            throw new InvalidArgumentException('Query has to be array or string not '.gettype($query));
        }

        if ($query === '') {
            return [];
        }

        $normalized = ltrim($query, '?');

        $items = [];
        parse_str($normalized, $items);

        // If the query starts with a ? overwrite the complete url
        if ($query[0] == '?') {
            return $items;
        }

        return array_merge($this->query, $items);
    }