public function withQuery($query): self
    {
        if (!\is_string($query) && !method_exists($query, '__toString')) {
            throw new \InvalidArgumentException('Uri query must be a string');
        }
        $query        = ltrim((string)$query, '?');
        $clone        = clone $this;
        $clone->query = $this->filterQuery($query);

        return $clone;
    }