Completed
Push — master ( 065cdd...96faaf )
by Alejandro
09:28
created

ImageFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 26
rs 10
wmc 4
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 4
1
<?php
2
namespace Shlinkio\Shlink\Common\Image;
3
4
use Interop\Container\ContainerInterface;
5
use Interop\Container\Exception\ContainerException;
6
use mikehaertl\wkhtmlto\Image;
7
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
8
use Zend\ServiceManager\Exception\ServiceNotFoundException;
9
use Zend\ServiceManager\Factory\FactoryInterface;
10
11
class ImageFactory implements FactoryInterface
12
{
13
    /**
14
     * Create an object
15
     *
16
     * @param  ContainerInterface $container
17
     * @param  string $requestedName
18
     * @param  null|array $options
19
     * @return object
20
     * @throws ServiceNotFoundException if unable to resolve the service.
21
     * @throws ServiceNotCreatedException if an exception is raised when
22
     *     creating a service.
23
     * @throws ContainerException if any other error occurs
24
     */
25
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
26
    {
27
        $config = $container->get('config')['phpwkhtmltopdf'];
28
        $image = new Image(isset($config['images']) ? $config['images'] : null);
29
30
        if (isset($options) && isset($options['url'])) {
31
            $image->setPage($options['url']);
32
        }
33
34
        return $image;
35
    }
36
}
37