AbstractDetector   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 47
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createInstance() 0 3 1
A detect() 0 6 2
1
<?php
2
3
namespace ImageMimeTypeGuesser\Detectors;
4
5
use ImageMimeTypeGuesser\Detectors\AbstractDetector;
6
7
abstract class AbstractDetector
8
{
9
    /**
10
     * Try to detect mime type of image
11
     *
12
     * Returns:
13
     * - mime type (string) (if it is in fact an image, and type could be determined)
14
     * - false (if it is not an image type that the server knowns about)
15
     * - null  (if nothing can be determined)
16
     *
17
     * @param  string  $filePath  The path to the file
18
     * @return string|false|null  mimetype (if it is an image, and type could be determined),
19
     *    false (if it is not an image type that the server knowns about)
20
     *    or null (if nothing can be determined)
21
     */
22
    abstract protected function doDetect($filePath);
23
24
    /**
25
     * Create an instance of this class
26
     *
27
     * @param  string  $filePath  The path to the file
28
     * @return static
29
     */
30 19
    public static function createInstance()
31
    {
32 19
        return new static();
33
    }
34
35
    /**
36
     * Detect mime type of file (for images only)
37
     *
38
     * Returns:
39
     * - mime type (string) (if it is in fact an image, and type could be determined)
40
     * - false (if it is not an image type that the server knowns about)
41
     * - null  (if nothing can be determined)
42
     *
43
     * @param  string  $filePath  The path to the file
44
     * @return string|false|null  mimetype (if it is an image, and type could be determined),
45
     *    false (if it is not an image type that the server knowns about)
46
     *    or null (if nothing can be determined)
47
     */
48 20
    public static function detect($filePath)
49
    {
50 20
        if (!@file_exists($filePath)) {
51 10
            return false;
52
        }
53 19
        return self::createInstance()->doDetect($filePath);
54
    }
55
}
56