public static function guess(string $filename): ?string
    {
        if (! \is_file($filename)) {
            throw new FileNotFoundException($filename);
        }

        if (! \is_readable($filename)) {
            throw new AccessDeniedException($filename);
        }

        if (self::$magicFile !== null) {
            $finfo = \finfo_open(\FILEINFO_MIME_TYPE, self::$magicFile);
        } else {
            $finfo = \finfo_open(\FILEINFO_MIME_TYPE);
        }

        $type = \finfo_file($finfo, $filename);

        \finfo_close($finfo);

        return $type ?? null;
    }