Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
MimeType
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 getMimeTypeDetectionResult
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace WebPConvert\Helpers;
4
5use ImageMimeTypeGuesser\ImageMimeTypeGuesser;
6
7use WebPConvert\Exceptions\InvalidInputException;
8use WebPConvert\Exceptions\InvalidInput\TargetNotFoundException;
9
10/**
11 * Get MimeType, results cached by path.
12 *
13 * @package    WebPConvert
14 * @author     Bjørn Rosell <it@rosell.dk>
15 * @since      Class available since Release 2.0.6
16 */
17class MimeType
18{
19    private static $cachedDetections = [];
20
21    /**
22     * Get mime type for image (best guess).
23     *
24     * It falls back to using file extension. If that fails too, false is returned
25     *
26     * @return  string|false|null mimetype (if it is an image, and type could be determined / guessed),
27     *    false (if it is not an image type that the server knowns about)
28     *    or null (if nothing can be determined)
29     */
30    public static function getMimeTypeDetectionResult($absFilePath)
31    {
32        PathChecker::checkAbsolutePathAndExists($absFilePath);
33
34        if (isset(self::$cachedDetections[$absFilePath])) {
35            return self::$cachedDetections[$absFilePath];
36        }
37        self::$cachedDetections[$absFilePath] = ImageMimeTypeGuesser::lenientGuess($absFilePath);
38        return self::$cachedDetections[$absFilePath];
39    }
40}