Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Less_Mime
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
4
100.00% covered (success)
100.00%
1 / 1
 lookup
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 charsets_lookup
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2declare( strict_types = 1 );
3
4/**
5 * Mime lookup
6 *
7 * @private
8 */
9class Less_Mime {
10
11    /**
12     * this map is intentionally incomplete
13     * if you want more, install 'mime' dep
14     * @var array<string,string>
15     */
16    private static $types = [
17        '.htm' => 'text/html',
18        '.html' => 'text/html',
19        '.gif' => 'image/gif',
20        '.jpg' => 'image/jpeg',
21        '.jpeg' => 'image/jpeg',
22        '.png' => 'image/png',
23        '.ttf' => 'application/x-font-ttf',
24        '.otf' => 'application/x-font-otf',
25        '.eot' => 'application/vnd.ms-fontobject',
26        '.woff' => 'application/x-font-woff',
27        '.svg' => 'image/svg+xml',
28    ];
29
30    public static function lookup( $filepath ) {
31        $parts = explode( '.', $filepath );
32        $ext = '.' . strtolower( array_pop( $parts ) );
33
34        return self::$types[$ext] ?? null;
35    }
36
37    public static function charsets_lookup( $type = null ) {
38        // assumes all text types are UTF-8
39        return $type && preg_match( '/^text\//', $type ) ? 'UTF-8' : '';
40    }
41}