Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AbstractDetector | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| doDetect | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| createInstance | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| detect | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace ImageMimeTypeGuesser\Detectors; |
| 4 | |
| 5 | abstract class AbstractDetector |
| 6 | { |
| 7 | /** |
| 8 | * Try to detect mime type of image |
| 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 | abstract protected function doDetect($filePath); |
| 21 | |
| 22 | /** |
| 23 | * Create an instance of this class |
| 24 | * |
| 25 | * @return static |
| 26 | */ |
| 27 | public static function createInstance() |
| 28 | { |
| 29 | return new static(); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Detect mime type of file (for images only) |
| 34 | * |
| 35 | * Returns: |
| 36 | * - mime type (string) (if it is in fact an image, and type could be determined) |
| 37 | * - false (if it is not an image type that the server knowns about) |
| 38 | * - null (if nothing can be determined) |
| 39 | * |
| 40 | * @param string $filePath The path to the file |
| 41 | * @return string|false|null mimetype (if it is an image, and type could be determined), |
| 42 | * false (if it is not an image type that the server knowns about) |
| 43 | * or null (if nothing can be determined) |
| 44 | */ |
| 45 | public static function detect($filePath) |
| 46 | { |
| 47 | if (!@file_exists($filePath)) { |
| 48 | return false; |
| 49 | } |
| 50 | return self::createInstance()->doDetect($filePath); |
| 51 | } |
| 52 | } |