ApplicationFactory   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\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\Exception\ContainerException;
8
use Symfony\Component\Console\Application as CliApp;
9
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
10
use Zend\ServiceManager\Exception\ServiceNotFoundException;
11
use Zend\ServiceManager\Factory\FactoryInterface;
12
13
class ApplicationFactory implements FactoryInterface
14
{
15
    /**
16
     * Create an object
17
     *
18
     * @param  ContainerInterface $container
19
     * @param  string $requestedName
20
     * @param  null|array $options
21
     * @return object|CliApp
22
     * @throws ServiceNotFoundException if unable to resolve the service.
23
     * @throws ServiceNotCreatedException if an exception is raised when
24
     *     creating a service.
25
     * @throws ContainerException if any other error occurs
26
     */
27
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): CliApp
28
    {
29
        $config = $container->get('config')['cli'];
30
        $commands = $config['commands'] ?? [];
31
32
        $app = new CliApp();
33
        foreach ($commands as $command) {
34
            if (! $container->has($command)) {
35
                continue;
36
            }
37
38
            $app->add($container->get($command));
39
        }
40
41
        return $app;
42
    }
43
}
44