ImageOptimiserServiceFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 25 5
1
<?php
2
3
namespace Rvdlee\ZfImageOptimiser\Factory\Service;
4
5
use Interop\Container\ContainerInterface;
6
use Rvdlee\ZfImageOptimiser\Exception\InvalidArgumentException;
7
use Rvdlee\ZfImageOptimiser\Exception\InvalidConfigurationException;
8
use Rvdlee\ZfImageOptimiser\Interfaces\ImageOptimiserInterface;
9
use Rvdlee\ZfImageOptimiser\Service\ImageOptimiserService;
10
use Zend\Log\Logger;
0 ignored issues
show
Bug introduced by
The type Zend\Log\Logger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Zend\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Zend\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Zend\Log\Writer\Mock;
0 ignored issues
show
Bug introduced by
The type Zend\Log\Writer\Mock was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Zend\Log\Writer\Stream;
0 ignored issues
show
Bug introduced by
The type Zend\Log\Writer\Stream was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Zend\ServiceManager\Factory\FactoryInterface;
15
16
class ImageOptimiserServiceFactory implements FactoryInterface
17
{
18
    /**
19
     * @param ContainerInterface $container
20
     * @param string             $requestedName
21
     * @param array|null         $options
22
     *
23
     * @return object|ImageOptimiserService
24
     * @throws InvalidConfigurationException
25
     * @throws InvalidArgumentException
26
     */
27
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
28
    {
29
        /** @var array|ImageOptimiserInterface $adapters */
30
        $adapters = [];
31
        /** @var array $config */
32
        $config = $container->get('config');
33
34
        if ( ! isset($config['rvdlee']['zf-image-optimiser']['enabled'])) {
35
            throw new InvalidConfigurationException('We are missing configuration to make this code work.');
36
        }
37
38
        foreach ($config['rvdlee']['zf-image-optimiser']['enabled'] as $adapter) {
39
            $adapters[] = $container->get($adapter);
40
        }
41
42
        if (isset($options['logger']) && $options['logger'] instanceof LoggerInterface) {
43
            $logger = $options['logger'];
44
        } else {
45
            /** @var Logger $logger */
46
            $logger = $container->get(Logger::class);
47
            /** @var Stream $writer */
48
            $logger->addWriter(new Mock());
49
        }
50
51
        return new ImageOptimiserService($adapters, $logger);
52
    }
53
}