protected static function removeDotSegments(string $path): string
    {
        $output = '';
        while ($path) {
            if ('..' == $path || '.' == $path) {
                break;
            }
            switch (true) {
                case ('./' == substr($path, 0, 2)):
                    $path = substr($path, 2);
                    break;
                case ('../' == substr($path, 0, 3)):
                    $path = substr($path, 3);
                    break;
                case ('/./' == substr($path, 0, 3)):
                    $path = substr($path, 2);
                    break;
                case ('/../' == substr($path, 0, 4)):
                    $path = '/'.substr($path, 4);
                    $pos = strrpos($output, '/', -1);
                    if ($pos !== false) {
                        $output = substr($output, 0, $pos);
                    }
                    break;
                case ('/..' == substr($path, 0, 3) && (in_array(substr($path, 3, 1), [false, '', '/'], true))):
                    $path = '/'.substr($path, 3);
                    $pos = strrpos($output, '/', -1);
                    if ($pos !== false) {
                        $output = substr($output, 0, $pos);
                    }
                    break;
                case ('/.' == substr($path, 0, 2) && (in_array(substr($path, 2, 1), [false, '', '/'], true))):
                    $path = '/'.substr($path, 2);
                    break;
                default:
                    $nextSlash = strpos($path, '/', 1);
                    if (false === $nextSlash) {
                        $segment = $path;
                    } else {
                        $segment = substr($path, 0, $nextSlash);
                    }
                    $output .= $segment;
                    $path = substr($path, strlen($segment));
                    break;
            }
        }

        return $output;
    }