Stack::doDetect()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 3
b 0
f 0
nc 3
nop 1
dl 0
loc 21
ccs 7
cts 8
cp 0.875
crap 3.0175
rs 9.8666
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