detectMimeTypeFromBuffer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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