ImagineFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 31
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 19 4
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright https://yawik.org/COPYRIGHT.php
8
 */
9
10
/** */
11
namespace Core\Factory\Service;
12
13
use Core\Options\ImagineOptions;
14
use Interop\Container\ContainerInterface;
15
use Laminas\ServiceManager\Factory\FactoryInterface;
16
17
/**
18
 * Factory for Imagine service.
19
 *
20
 * @author Mathias Gelhausen <[email protected]>
21
 * @since 0.29
22
 */
23
class ImagineFactory implements FactoryInterface
24
{
25
    /**
26
     *
27
     *
28
     * @param ContainerInterface $container
29
     * @param string             $requestedName
30
     * @param array              $options
31
     *
32
     * @return \Imagine\Image\ImagineInterface
33
     * @throws \UnexpectedValueException
34
     */
35 4
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
36
    {
37 4
        $options = $container->get(ImagineOptions::class);
38 4
        $lib     = $options->getImageLib();
39
40 4
        switch ($lib) {
41
            default:
42 1
                throw new \UnexpectedValueException('Unsupported image library specified.');
43
                break;
44
45
            case ImagineOptions::LIB_GD:
46
            case ImagineOptions::LIB_IMAGICK:
47
            case ImagineOptions::LIB_GMAGICK:
48 3
                $imagineClass = '\Imagine\\' . $lib . '\Imagine';
49 3
                $imagine = new $imagineClass;
50 1
                break;
51
        }
52
53 1
        return $imagine;
54
    }
55
}
56