Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Stack | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
3.00 | |
0.00% |
0 / 1 |
| doDetect | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
3.00 | |||
| 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 | protected function doDetect($filePath) |
| 21 | { |
| 22 | $detectors = [ |
| 23 | 'SignatureSniffer', |
| 24 | 'FInfo', |
| 25 | 'ExifImageType', |
| 26 | //'GetImageSize', // Disabled, as documentation says it is unreliable |
| 27 | 'MimeContentType', |
| 28 | ]; |
| 29 | |
| 30 | foreach ($detectors as $className) { |
| 31 | $result = call_user_func( |
| 32 | array("\\ImageMimeTypeGuesser\\Detectors\\" . $className, 'detect'), |
| 33 | $filePath |
| 34 | ); |
| 35 | if (!is_null($result)) { |
| 36 | return $result; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return null; // undetermined |
| 41 | } |
| 42 | } |