| Total Complexity | 6 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class Conversion |
||
| 10 | { |
||
| 11 | private string $conversionTo = 'default'; |
||
| 12 | private array $allowFormatConversion = ['webp','png','jpeg']; |
||
| 13 | |||
| 14 | public function get(): string |
||
| 15 | { |
||
| 16 | return $this->conversionTo; |
||
| 17 | } |
||
| 18 | |||
| 19 | public function set(string $conversionTo) |
||
| 20 | { |
||
| 21 | try { |
||
| 22 | if (!in_array($conversionTo, $this->allowFormatConversion, true)) { |
||
| 23 | throw new \Exception("Don't exist format to conversion (" . $conversionTo . ')'); |
||
| 24 | } |
||
| 25 | } catch (\Exception $e) { |
||
| 26 | $conversionTo = 'png'; |
||
| 27 | ResponseHandler::fail($e->getMessage()); |
||
| 28 | } finally { |
||
| 29 | $this->conversionTo = $conversionTo; |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | public function transform($imagecreatefrom, string $transformImage, array $imageArray) |
||
| 37 | } |
||
| 38 | } |
||
| 39 |