CliFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 53
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventManager() 0 12 2
A __invoke() 0 13 1
A createService() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModule\Service;
6
7
use Interop\Container\ContainerInterface;
8
use Laminas\EventManager\EventManagerInterface;
9
use Laminas\ServiceManager\FactoryInterface;
10
use Laminas\ServiceManager\ServiceLocatorInterface;
11
use Symfony\Component\Console\Application;
12
use Symfony\Component\Console\Helper\HelperSet;
13
14
/**
15
 * CLI Application ServiceManager factory responsible for instantiating a Symfony CLI application
16
 *
17
 * @link    http://www.doctrine-project.org/
18
 */
19
class CliFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Laminas\ServiceManager\FactoryInterface has been deprecated with message: Use Laminas\ServiceManager\Factory\FactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
20
{
21
    /** @var EventManagerInterface */
22
    protected $events;
23
24
    /** @var HelperSet */
25
    protected $helperSet;
26
27
    /** @var mixed[] */
28
    protected $commands = [];
29
30
    public function getEventManager(ContainerInterface $container) : EventManagerInterface
31
    {
32
        if ($this->events === null) {
33
            $events = $container->get('EventManager');
34
35
            $events->addIdentifiers([self::class, 'doctrine']);
36
37
            $this->events = $events;
38
        }
39
40
        return $this->events;
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     *
46
     * @return Application
47
     */
48
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
49
    {
50
        $cli = new Application();
51
        $cli->setName('DoctrineModule Command Line Interface');
52
        $cli->setHelperSet(new HelperSet());
53
        $cli->setCatchExceptions(true);
54
        $cli->setAutoExit(false);
55
56
        // Load commands using event
57
        $this->getEventManager($container)->trigger('loadCli.post', $cli, ['ServiceManager' => $container]);
58
59
        return $cli;
60
    }
61
62
    /**
63
     * {@inheritDoc}
64
     *
65
     * @return Application
66
     */
67
    public function createService(ServiceLocatorInterface $container)
68
    {
69
        return $this($container, Application::class);
70
    }
71
}
72