Passed
Push — master ( 2d60b9...33913d )
by Bjørn
01:46
created

src/Detectors/ExifImageType.php (1 issue)

1
<?php
2
3
namespace ImageMimeTypeGuesser\Detectors;
4
5
use \ImageMimeTypeGuesser\Detectors\AbstractDetector;
6
7
class ExifImageType extends AbstractDetector
8
{
9
10
    /**
11
     *  Try to detect mime type of image using "exif_imagetype"
12
     *
13
     *  Like all detectors, it returns:
14
     *  - null  (if it cannot be determined)
15
     *  - false (if it can be determined that this is not an image)
16
     *  - mime  (if it is in fact an image, and type could be determined)
17
     *  @return  mime | null | false.
0 ignored issues
show
Documentation Bug introduced by
The doc comment mime | null | false. at position 4 could not be parsed: Unknown type name 'false.' at position 4 in mime | null | false..
Loading history...
18
     */
19
    protected function doDetect($filePath)
20
    {
21
        // exif_imagetype is fast, however not available on all systems,
22
        // It may return false. In that case we can rely on that the file is not an image (and return false)
23
        if (function_exists('exif_imagetype')) {
24
            try {
25
                $imageType = exif_imagetype($filePath);
26
                return ($imageType ? image_type_to_mime_type($imageType) : false);
27
            } catch (\Exception $e) {
28
                // Might for example get "Read error!"
29
                // well well, don't let this stop us
30
                //echo $e->getMessage();
31
//                throw($e);
32
            }
33
        }
34
        return;
35
    }
36
}
37