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

ImagineFactory::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 11
ccs 0
cts 11
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
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
}