GetImageSize   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 30
ccs 7
cts 7
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A doDetect() 0 14 4
1
<?php
2
3
namespace ImageMimeTypeGuesser\Detectors;
4
5
class GetImageSize extends AbstractDetector
6
{
7
8
    /**
9
     * Try to detect mime type of image using *getimagesize()*.
10
     *
11
     * Returns:
12
     * - mime type (string) (if it is in fact an image, and type could be determined)
13
     * - false (if it is not an image type that the server knowns about)
14
     * - null  (if nothing can be determined)
15
     *
16
     * @param  string  $filePath  The path to the file
17
     * @return string|false|null  mimetype (if it is an image, and type could be determined),
18
     *    false (if it is not an image type that the server knowns about)
19
     *    or null (if nothing can be determined)
20
     */
21 2
    protected function doDetect($filePath)
22
    {
23
        // getimagesize is slower than exif_imagetype
24
        // It may not return "mime". In that case we can rely on that the file is not an image (and return false)
25 2
        if (function_exists('getimagesize')) {
26
            try {
27 1
                $imageSize = getimagesize($filePath);
28 1
                return (isset($imageSize['mime']) ? $imageSize['mime'] : false);
29 1
            } catch (\Exception $e) {
30
                // well well, don't let this stop us either
31 1
                return null;
32
            }
33
        }
34 1
        return null;
35
    }
36
}
37