Conditions | 2 |
Paths | 2 |
Total Lines | 18 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
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 |