GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MimeTypeGuesser::guess()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 9
cp 0
cc 2
eloc 10
nc 4
nop 1
crap 6
1
<?php
2
namespace HtImgModule\Binary;
3
4
use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface as SymfonyMimeTypeGuesserInterface;
5
6
class MimeTypeGuesser
7
{
8
    /**
9
     * @var SymfonyMimeTypeGuesserInterface
10
     */
11
    protected $mimeTypeGuesser;
12
13
    /**
14
     * @param SymfonyMimeTypeGuesserInterface $mimeTypeGuesser
15
     */
16 1
    public function __construct(SymfonyMimeTypeGuesserInterface $mimeTypeGuesser)
17
    {
18 1
        $this->mimeTypeGuesser = $mimeTypeGuesser;
19 1
    }
20
21
    /**
22
     * Gets mime type of binary
23
     *
24
     * @param  string     $binary
25
     * @return string
26
     * @throws \Exception
27
     */
28
    public function guess($binary)
29
    {
30
        $tmpFile = tempnam(sys_get_temp_dir(), 'ht-img-module');
31
32
        try {
33
            file_put_contents($tmpFile, $binary);
34
35
            $mimeType = $this->mimeTypeGuesser->guess($tmpFile);
36
37
            unlink($tmpFile);
38
39
            return $mimeType;
40
        } catch (\Exception $e) {
41
            unlink($tmpFile);
42
43
            throw $e;
44
        }
45
    }
46
}
47