| Total Complexity | 4 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | trait ValidatesBase64 |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Reads mime type of string by using file info buffer. |
||
| 9 | * |
||
| 10 | * @param string $value |
||
| 11 | * @return string |
||
| 12 | */ |
||
| 13 | protected static function getMimeType(string $value): string |
||
| 14 | { |
||
| 15 | $fileData = base64_decode(static::removeScheme($value)); |
||
| 16 | |||
| 17 | $f = finfo_open(); |
||
| 18 | |||
| 19 | $mimeType = finfo_buffer($f, $fileData, FILEINFO_MIME_TYPE); |
||
| 20 | |||
| 21 | finfo_close($f); |
||
| 22 | |||
| 23 | return $mimeType; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Removes data scheme from base64. |
||
| 28 | * |
||
| 29 | * @param string $value |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | protected static function removeScheme(string $value): string |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns the size of a base64 string in kilobytes. |
||
| 45 | * |
||
| 46 | * @param string $value |
||
| 47 | * @return float |
||
| 48 | */ |
||
| 49 | protected function getSize(string $value): float |
||
| 52 | } |
||
| 53 | } |
||
| 54 |