Stack   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 13
c 4
b 0
f 0
dl 0
loc 36
ccs 7
cts 8
cp 0.875
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A doDetect() 0 21 3
1
<?php
2
3
namespace ImageMimeTypeGuesser\Detectors;
4
5
class Stack extends AbstractDetector
6
{
7
    /**
8
     * Try to detect mime type of image using all available detectors.
9
     *
10
     * Returns:
11
     * - mime type (string) (if it is in fact an image, and type could be determined)
12
     * - false (if it is not an image type that the server knowns about)
13
     * - null  (if nothing can be determined)
14
     *
15
     * @param  string  $filePath  The path to the file
16
     * @return string|false|null  mimetype (if it is an image, and type could be determined),
17
     *    false (if it is not an image type that the server knowns about)
18
     *    or null (if nothing can be determined)
19
     */
20 4
    protected function doDetect($filePath)
21
    {
22
        $detectors = [
23 4
            'FInfo',
24
            'SniffFirstFourBytes',
25
            'ExifImageType',
26
            //'GetImageSize',   // Disabled, as documentation says it is unreliable
27
            'MimeContentType',
28
        ];
29
30 4
        foreach ($detectors as $className) {
31 4
            $result = call_user_func(
32 4
                array("\\ImageMimeTypeGuesser\\Detectors\\" . $className, 'detect'),
33
                $filePath
34
            );
35 4
            if (!is_null($result)) {
36 4
                return $result;
37
            }
38
        }
39
40
        return null;     // undetermined
41
    }
42
}
43