private static function myParseUrlPath(?UrlInterface $baseUrl = null, string $pathString, ?UrlPathInterface &$path = null, ?string &$error = null): bool
    {
        // If path is empty and there is a base url, use the path from base url.
        if ($baseUrl !== null && $pathString === '') {
            $path = $baseUrl->getPath();

            return true;
        }

        // Parse path.
        try {
            $path = UrlPath::parse($pathString);
        } catch (UrlPathInvalidArgumentException $e) {
            $error = $e->getMessage();

            return false;
        }

        // If there is a base url, paths should be combined.
        if ($baseUrl !== null) {
            $path = $baseUrl->getPath()->withUrlPath($path);
        }

        return true;
    }