Completed
Push — master ( 1fd677...d734d1 )
by Alejandro
27s queued 11s
created

ImageFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 3
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\PreviewGenerator\Image;
5
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\Exception\ContainerException;
8
use mikehaertl\wkhtmlto\Image;
9
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
10
use Zend\ServiceManager\Exception\ServiceNotFoundException;
11
use Zend\ServiceManager\Factory\FactoryInterface;
12
13
/** @deprecated  */
14
class ImageFactory implements FactoryInterface
15
{
16
    /**
17
     * Create an object
18
     *
19
     * @param  ContainerInterface $container
20
     * @param  string $requestedName
21
     * @param  null|array $options
22
     * @return object
23
     * @throws ServiceNotFoundException if unable to resolve the service.
24
     * @throws ServiceNotCreatedException if an exception is raised when
25
     *     creating a service.
26
     * @throws ContainerException if any other error occurs
27
     */
28 2
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
29
    {
30 2
        $config = $container->get('config')['wkhtmltopdf'];
31 2
        $image = new Image($config['images'] ?? null);
32
33 2
        if ($options['url'] ?? null) {
34 1
            $image->setPage($options['url']);
35
        }
36
37 2
        return $image;
38
    }
39
}
40