Extension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
dl 0
loc 34
rs 10
c 1
b 0
f 1
ccs 10
cts 10
cp 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTypes() 0 7 2
A getDefaultType() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace FileEye\MimeMap;
4
5
use FileEye\MimeMap\Map\MimeMapInterface;
6
7
/**
8
 * Class for mapping file extensions to MIME types.
9
 */
10
class Extension implements ExtensionInterface
11
{
12
    /**
13
     * The file extension.
14
     *
15
     * @var string
16
     */
17
    protected $extension;
18
19
    /**
20
     * The MIME types map.
21
     *
22
     * @var MimeMapInterface
23
     */
24
    protected $map;
25
26 16
    public function __construct(string $extension, string $map_class = null)
27
    {
28 16
        $this->extension = strtolower($extension);
29 16
        $this->map = MapHandler::map($map_class);
30
    }
31
32 8
    public function getDefaultType(): string
33
    {
34 8
        return $this->getTypes()[0];
35
    }
36
37 16
    public function getTypes(): array
38
    {
39 16
        $types = $this->map->getExtensionTypes($this->extension);
40 16
        if (!empty($types)) {
41 8
            return $types;
42
        }
43 8
        throw new MappingException('No MIME type mapped to extension ' . $this->extension);
44
    }
45
}
46