<commit_before><?php

namespace Becklyn\AssetsBundle\File;


use Becklyn\AssetsBundle\Asset\Asset;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;


class AssetMimeTypeGuesser
{
    /**
     * @var array
     */
    private static $mimeTypes = [
        'txt' => 'text/plain',
        'htm' => 'text/html',
        'html' => 'text/html',
        'php' => 'text/html',
        'css' => 'text/css',
        'js' => 'application/javascript',
        'json' => 'application/json',
        'xml' => 'application/xml',
        'swf' => 'application/x-shockwave-flash',
        'flv' => 'video/x-flv',

        // images
        'png' => 'image/png',
        'jpe' => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'jpg' => 'image/jpeg',
        'gif' => 'image/gif',
        'bmp' => 'image/bmp',
        'ico' => 'image/vnd.microsoft.icon',
        'tiff' => 'image/tiff',
        'tif' => 'image/tiff',
        'svg' => 'image/svg+xml',
        'svgz' => 'image/svg+xml',

        // archives
        'zip' => 'application/zip',
        'rar' => 'application/x-rar-compressed',
        'exe' => 'application/x-msdownload',
        'msi' => 'application/x-msdownload',
        'cab' => 'application/vnd.ms-cab-compressed',

        // audio/video
        'mp3' => 'audio/mpeg',
        'qt' => 'video/quicktime',
        'mov' => 'video/quicktime',

        // adobe
        'pdf' => 'application/pdf',
        'psd' => 'image/vnd.adobe.photoshop',
        'ai' => 'application/postscript',
        'eps' => 'application/postscript',
        'ps' => 'application/postscript',

        // ms office
        'doc' => 'application/msword',
        'rtf' => 'application/rtf',
        'xls' => 'application/vnd.ms-excel',
        'ppt' => 'application/vnd.ms-powerpoint',

        // open office
        'odt' => 'application/vnd.oasis.opendocument.text',
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
    ];


    /**
     * @var MimeTypeGuesser
     */
    private $coreGuesser;


    /**
     *
     */
    public function __construct ()
    {
        $this->coreGuesser = MimeTypeGuesser::getInstance();
    }


    /**
     * Guesses the mime type.
     *
     * @param Asset $asset
     * @return string
     */
    public function guess (Asset $asset) : string
    {
        try
        {
            $predefinedType = self::$mimeTypes[$asset->getFileType()] ?? null;

            if (null !== $predefinedType)
            {
                return $predefinedType;
            }

            return $this->coreGuesser->guess($asset->getFilePath());
        }
        catch (Exception $e)
        {
            return "application/octet-stream";
        }
    }
}
<commit_msg>Fix mime type guesser + add font types<commit_after><?php

namespace Becklyn\AssetsBundle\File;

use Becklyn\AssetsBundle\Asset\Asset;
use Becklyn\AssetsBundle\Exception\AssetsException;
use Becklyn\AssetsBundle\Namespaces\NamespaceRegistry;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;


class AssetMimeTypeGuesser
{
    /**
     * @var array
     */
    private static $mimeTypes = [
        'txt' => 'text/plain',
        'htm' => 'text/html',
        'html' => 'text/html',
        'php' => 'text/html',
        'css' => 'text/css',
        'js' => 'application/javascript',
        'json' => 'application/json',
        'xml' => 'application/xml',
        'swf' => 'application/x-shockwave-flash',
        'flv' => 'video/x-flv',

        // fonts
        'woff' => 'application/font-woff',
        'woff2' => 'application/font-woff2',
        'ttf' => 'application/x-font-truetype',
        'otf' => 'application/x-font-opentype',
        'eot' => 'application/vnd.ms-fontobject',

        // images
        'png' => 'image/png',
        'jpe' => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'jpg' => 'image/jpeg',
        'gif' => 'image/gif',
        'bmp' => 'image/bmp',
        'ico' => 'image/vnd.microsoft.icon',
        'tiff' => 'image/tiff',
        'tif' => 'image/tiff',
        'svg' => 'image/svg+xml',
        'svgz' => 'image/svg+xml',

        // archives
        'zip' => 'application/zip',
        'rar' => 'application/x-rar-compressed',
        'exe' => 'application/x-msdownload',
        'msi' => 'application/x-msdownload',
        'cab' => 'application/vnd.ms-cab-compressed',

        // audio/video
        'mp3' => 'audio/mpeg',
        'qt' => 'video/quicktime',
        'mov' => 'video/quicktime',

        // adobe
        'pdf' => 'application/pdf',
        'psd' => 'image/vnd.adobe.photoshop',
        'ai' => 'application/postscript',
        'eps' => 'application/postscript',
        'ps' => 'application/postscript',

        // ms office
        'doc' => 'application/msword',
        'rtf' => 'application/rtf',
        'xls' => 'application/vnd.ms-excel',
        'ppt' => 'application/vnd.ms-powerpoint',

        // open office
        'odt' => 'application/vnd.oasis.opendocument.text',
        'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
    ];


    /**
     * @var MimeTypeGuesser
     */
    private $coreGuesser;


    /**
     * @var NamespaceRegistry
     */
    private $namespaceRegistry;


    /**
     * @param NamespaceRegistry $namespaceRegistry
     */
    public function __construct (NamespaceRegistry $namespaceRegistry)
    {
        $this->coreGuesser = MimeTypeGuesser::getInstance();
        $this->namespaceRegistry = $namespaceRegistry;
    }


    /**
     * Guesses the mime type.
     *
     * @param Asset $asset
     * @return string
     */
    public function guess (Asset $asset) : string
    {
        try
        {
            $predefinedType = self::$mimeTypes[$asset->getFileType()] ?? null;

            if (null !== $predefinedType)
            {
                return $predefinedType;
            }

            $filePath = $this->namespaceRegistry->getFilePath($asset);
            return $this->coreGuesser->guess($filePath);
        }
        catch (AssetsException | Exception $e)
        {
            return "application/octet-stream";
        }
    }
}

{'fraction_non_alphanumeric': 0.1719826895335791, 'fraction_numerical': 0.0006411283859592883, 'mean_word_length': 1.96437054631829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3718055', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1977, 'n_words': 323}