ExtensionMimeTypeDetector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A detectMimeTypeFromFile() 0 3 1
A detectMimeTypeFromPath() 0 5 1
A detectMimeType() 0 3 1
A detectMimeTypeFromBuffer() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\MimeTypeDetection;
6
7
use const PATHINFO_EXTENSION;
8
9
class ExtensionMimeTypeDetector implements MimeTypeDetector
10
{
11
    /**
12
     * @var ExtensionToMimeTypeMap
13
     */
14
    private $extensions;
15
16 24
    public function __construct(ExtensionToMimeTypeMap $extensions = null)
17
    {
18 24
        $this->extensions = $extensions ?: new GeneratedExtensionToMimeTypeMap();
19 24
    }
20
21 18
    public function detectMimeType(string $path, $contents): ?string
22
    {
23 18
        return $this->detectMimeTypeFromPath($path);
24
    }
25
26 18
    public function detectMimeTypeFromPath(string $path): ?string
27
    {
28 18
        $extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
29
30 18
        return $this->extensions->lookupMimeType($extension);
31
    }
32
33 18
    public function detectMimeTypeFromFile(string $path): ?string
34
    {
35 18
        return $this->detectMimeTypeFromPath($path);
36
    }
37
38 6
    public function detectMimeTypeFromBuffer(string $contents): ?string
39
    {
40 6
        return null;
41
    }
42
}
43