LongTaskCommandFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Console\Command;
5
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\Exception\ContainerException;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
use Zend\ServiceManager\Exception\ServiceNotFoundException;
10
use Zend\ServiceManager\Factory\FactoryInterface;
11
12
class LongTaskCommandFactory implements FactoryInterface
13
{
14
    /**
15
     * Create an object
16
     *
17
     * @param  ContainerInterface $container
18
     * @param  string $requestedName
19
     * @param  null|array $options
20
     * @return LongTasksCommand|object
21
     * @throws ServiceNotFoundException if unable to resolve the service.
22
     * @throws ServiceNotCreatedException if an exception is raised when
23
     *     creating a service.
24
     * @throws ContainerException if any other error occurs
25
     */
26
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): LongTasksCommand
27
    {
28
        $config = $container->get('config')['long_tasks'];
29
        $tasks = $config['tasks'] ?? [];
30
31
        foreach ($tasks as $key => $task) {
32
            if (! $container->has($task)) {
33
                unset($tasks[$key]);
34
                continue;
35
            }
36
37
            $tasks[$key] = $container->get($task);
38
        }
39
40
        return new LongTasksCommand($tasks);
41
    }
42
}
43