Conditions | 4 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 4.0092 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 6 | protected function doDetect($filePath) |
|
22 | { |
||
23 | |||
24 | 6 | if (class_exists('finfo')) { |
|
25 | // phpcs:ignore PHPCompatibility.PHP.NewClasses.finfoFound |
||
26 | 5 | $finfo = new \finfo(FILEINFO_MIME); |
|
27 | 5 | $result = $finfo->file($filePath); |
|
28 | 5 | if ($result === false) { |
|
29 | // false means an error occured |
||
30 | return null; |
||
31 | } else { |
||
32 | 5 | $mime = explode('; ', $result); |
|
33 | 5 | $result = $mime[0]; |
|
34 | |||
35 | 5 | if (strpos($result, 'image/') === 0) { |
|
36 | 5 | return $result; |
|
37 | } else { |
||
38 | 3 | return false; |
|
39 | } |
||
40 | } |
||
41 | } |
||
42 | 1 | return null; |
|
43 | } |
||
45 |