Completed
Push — master ( 75a19d...cd945c )
by Kanstantsin
02:31
created

ImagineFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 11 4
1
<?php
2
3
namespace tkanstantsin\fileupload\formatter;
4
5
use Imagine\Gd\Imagine as GdImagine;
6
use Imagine\Gmagick\Imagine as GmagickImagine;
7
use Imagine\Image\ImagineInterface;
8
use Imagine\Imagick\Imagine as ImagickImagine;
9
use tkanstantsin\fileupload\config\InvalidConfigException;
10
11
/**
12
 * Class ImageDriverFactory
13
 */
14
class ImagineFactory
15
{
16
    /* Available driver */
17
    public const GD = 'gd';
18
    public const IMAGICK = 'imagick';
19
    public const GMAGICK = 'gmagick';
20
21
    /**
22
     * Create imagine object for given driver
23
     * @param string $type
24
     * @return ImagineInterface
25
     * @throws \Imagine\Exception\RuntimeException
26
     * @throws InvalidConfigException
27
     */
28
    public static function get(string $type): ImagineInterface
29
    {
30
        switch ($type) {
31
            case self::GD:
32
                return new GdImagine();
33
            case self::IMAGICK:
34
                return new ImagickImagine();
35
            case self::GMAGICK:
36
                return new GmagickImagine();
37
            default:
38
                throw new InvalidConfigException(sprintf('Image driver %s not found.', $type));
39
        }
40
    }
41
}