MimeTypeDetector::detectForFilename()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\HttpServer\MimeType;
11
12
use Mimey\MimeTypes;
13
14
final class MimeTypeDetector
15
{
16
    /**
17
     * @var MimeTypes
18
     */
19
    private $mimeTypes;
20
21 8
    public function __construct(MimeTypes $mimeTypes)
22
    {
23 8
        $this->mimeTypes = $mimeTypes;
24 8
    }
25
26 2
    public function detectForFilename(string $filemame) : string
27
    {
28 2
        if ($extension = pathinfo($filemame, PATHINFO_EXTENSION)) {
29 2
            if ($guessedType = $this->mimeTypes->getMimeType($extension)) {
30 2
                return $guessedType;
31
            }
32
        }
33
34 1
        return 'application/octet-stream';
35
    }
36
}
37