Completed
Pull Request — develop (#359)
by Mathias
23:51
created

ImagineFactory::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 3
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Factory\Service;
12
13
use Core\Options\ImagineOptions;
14
use Interop\Container\ContainerInterface;
15
use Zend\ServiceManager\FactoryInterface;
16
use Zend\ServiceManager\ServiceLocatorInterface;
17
18
/**
19
 * Factory for Imagine service.
20
 * 
21
 * @author Mathias Gelhausen <[email protected]>
22
 * @since 0.29
23
 */
24
class ImagineFactory implements FactoryInterface
25
{
26
    /**
27
     *
28
     *
29
     * @param ContainerInterface $container
30
     * @param string             $requestedName
31
     * @param array              $options
0 ignored issues
show
Documentation introduced by
Should the type for parameter $options not be null|array?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
32
     *
33
     * @return \Imagine\Image\ImagineInterface
34
     * @throws \UnexpectedValueException
35
     */
36
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
37
    {
38
        $options = $container->get(ImagineOptions::class);
39
        $lib     = $options->getImageLib();
40
41
        switch ($lib) {
42
            default:
43
                throw new \UnexpectedValueException('Unsupported image library specified.');
44
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
45
46
            case ImagineOptions::LIB_GD:
47
            case ImagineOptions::LIB_IMAGICK:
48
            case ImagineOptions::LIB_GMAGICK:
49
                $imagineClass = '\Imagine\\' . $lib . '\Imagine';
50
                $imagine = new $imagineClass;
51
                break;
52
        }
53
54
        return $imagine;
55
56
    }
57
58
    /**
59
     * Create service
60
     *
61
     * @param ServiceLocatorInterface $serviceLocator
62
     *
63
     * @return \Imagine\Image\ImagineInterface
64
     */
65
    public function createService(ServiceLocatorInterface $serviceLocator)
66
    {
67
        return $this($serviceLocator, 'Imagine');
68
    }
69
}