Passed
Pull Request — master (#2)
by mon
03:19
created

Extension::getDefaultType()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace FileEye\MimeMap;
4
5
/**
6
 * Class for mapping file extensions to MIME types.
7
 */
8
class Extension
9
{
10
    /**
11
     * Returns a file extension's MIME type.
12
     *
13
     * @param string $extension File extension to get the type of.
14
     *
15
     * @return string Extension's MIME type on success.
16
     */
17 3
    public function getDefaultType($extension)
18
    {
19 3
        $map = new TypeExtensionMap();
20 3
        $extension = strtolower($extension);
21 3
        if (!isset($map->get()['extensions'][$extension])) {
22 1
            throw new \RuntimeException("Sorry, couldn't determine file type.");
23
        }
24 2
        return $map->get()['extensions'][$extension][0];
25
    }
26
}
27