Completed
Push — master ( 1bd7cb...6e7c5d )
by David
12s
created

Manipulator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 20 5
A save() 0 20 5
1
<?php
2
3
namespace GNAHotelSolutions\ImageCacher;
4
5
class Manipulator
6
{
7
    public static function create(string $format, string $path)
8
    {
9
        if ($format === Format::JPEG) {
10
            return imagecreatefromjpeg($path);
11
        }
12
13
        if ($format === Format::PNG) {
14
            return imagecreatefrompng($path);
15
        }
16
17
        if ($format === Format::GIF) {
18
            return imagecreatefromgif($path);
19
        }
20
21
        if ($format === Format::WEBP) {
22
            return imagecreatefromwebp($path);
23
        }
24
25
        throw new \Exception("Image type [{$format}] not supported.");
26
    }
27
28
    public static function save(string $format, $layout, string $name): string
29
    {
30
        if ($format === Format::JPEG) {
31
            return imagejpeg($layout, $name);
32
        }
33
34
        if ($format === Format::PNG) {
35
            return imagepng($layout, $name);
36
        }
37
38
        if ($format === Format::GIF) {
39
            return imagegif($layout, $name);
40
        }
41
42
        if ($format === Format::WEBP) {
43
            return imagewebp($layout, $name);
44
        }
45
46
        throw new \Exception("Image type [{$format}] not supported.");
47
    }
48
}