Completed
Pull Request — master (#4)
by Timothy
14:57
created

Module::initializeConsole()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
ccs 14
cts 14
cp 1
rs 8.9197
cc 4
eloc 12
nc 4
nop 1
crap 4
1
<?php
2
3
namespace Abacaphiliac\DoctrineORMDiagnosticsModule;
4
5
use Symfony\Component\Console\Application;
6
use Zend\EventManager\EventInterface;
7
use Zend\ModuleManager\Feature\ConfigProviderInterface;
8
use Zend\ModuleManager\Feature\DependencyIndicatorInterface;
9
use Zend\ModuleManager\Feature\InitProviderInterface;
10
use Zend\ModuleManager\ModuleManagerInterface;
11
use Zend\ServiceManager\ServiceLocatorInterface;
12
13
class Module implements ConfigProviderInterface, DependencyIndicatorInterface, InitProviderInterface
14
{
15
    /**
16
     * Returns configuration to merge with application configuration
17
     *
18
     * @return array|\Traversable
19
     */
20 3
    public function getConfig()
21
    {
22 3
        return require dirname(dirname(__DIR__)) . '/config/module.config.php';
23
    }
24
25
    /**
26
     * Expected to return an array of modules on which the current one depends on
27
     *
28
     * @return array
29
     */
30 3
    public function getModuleDependencies()
31
    {
32
        return [
33 3
            'DoctrineModule',
34 3
            'DoctrineORMModule',
35 3
            'ZFTool',
36 3
        ];
37
    }
38
    
39
    /**
40
     * @param ModuleManagerInterface $manager
41
     */
42 2
    public function init(ModuleManagerInterface $manager)
43
    {
44 2
        $events = $manager->getEventManager();
45 2
        $sharedEventManager = $events->getSharedManager();
46 2
        $sharedEventManager->attach('doctrine', 'loadCli.post', [$this, 'initializeConsole']);
47 2
    }
48
49
    /**
50
     * Initialize the console with additional commands from (optionally) doctrine\migrations
51
     * @param EventInterface $event
52
     * @return bool
53
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
54
     */
55 5
    public function initializeConsole(EventInterface $event)
56
    {
57 5
        $cli = $event->getTarget();
58 5
        if (!$cli instanceof Application) {
59 1
            return false;
60
        }
61
        
62 4
        $serviceLocator = $event->getParam('ServiceManager');
63 4
        if (!$serviceLocator instanceof ServiceLocatorInterface) {
64 1
            return false;
65
        }
66
67 3
        if (class_exists('Doctrine\DBAL\Migrations\Tools\Console\Command\UpToDateCommand')) {
68 3
            $upToDateCommand = $serviceLocator->get('doctrine.migrations_cmd.uptodate');
69
            
70 3
            $cli->addCommands([
0 ignored issues
show
Documentation introduced by
array($upToDateCommand) is of type array<integer,object|array,{"0":"object|array"}>, but the function expects a array<integer,object<Sym...nsole\Command\Command>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71 3
                $upToDateCommand,
72 3
            ]);
73 3
        }
74
        
75 3
        return true;
76
    }
77
}
78