ImagineFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 27
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
    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
}