Test Failed
Push — master ( 9e6cf9...d006e3 )
by Petr
04:08
created

ImageExtensionChecker   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getExtensionFromBase64File() 0 18 2
1
<?php
2
3
namespace AppBundle\Service\File;
4
5
use AppBundle\Exception\UnsupportedTypeException;
6
7
/**
8
 * @author Vehsamrak
9
 */
10
class ImageExtensionChecker
11
{
12
13
    /**
14
     * @throws UnsupportedTypeException
15
     */
16
    public function getExtensionFromBase64File(string $image): string
17
    {
18
        $imageMap = [
19
            'image/png' => 'png',
20
            'image/gif' => 'gif',
21
            'image/jpeg' => 'jpeg',
22
        ];
23
24
        $imagedata = base64_decode($image);
25
        $image = finfo_open();
26
        $mimeType = finfo_buffer($image, $imagedata, FILEINFO_MIME_TYPE);
27
28
        if (!array_key_exists($mimeType, $imageMap)) {
29
        	throw new UnsupportedTypeException();
30
        }
31
32
        return $imageMap[$mimeType];
33
    }
34
}
35