private function createUri($uri): UriInterface
    {
        if ($uri instanceof UriInterface) {
            return $uri;
        }

        if (\is_string($uri)) {
            return Uri::createFromString($uri);
        }

        if ($uri === null) {
            return Uri::createFromString();
        }

        throw new InvalidArgumentException(
            'Invalid URI provided; must be null, a string or a [\Psr\Http\Message\UriInterface] instance.'
        );
    }