ImagineFactory::get()   A
last analyzed

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.9666
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
    public const DEFAULT_DRIVER = self::IMAGICK;
17
18
    /* Available drivers */
19
    public const GD = 'gd';
20
    public const IMAGICK = 'imagick';
21
    public const GMAGICK = 'gmagick';
22
23
    /**
24
     * Create imagine object for given driver
25
     * @param string $type
26
     * @return ImagineInterface
27
     * @throws \Imagine\Exception\RuntimeException
28
     * @throws InvalidConfigException
29
     */
30
    public static function get(string $type): ImagineInterface
31
    {
32
        switch ($type) {
33
            case self::GD:
34
                return new GdImagine();
35
            case self::IMAGICK:
36
                return new ImagickImagine();
37
            case self::GMAGICK:
38
                return new GmagickImagine();
39
            default:
40
                throw new InvalidConfigException(sprintf('Image driver %s not found.', $type));
41
        }
42
    }
43
}