ServiceManagerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 4 1
A getServiceManager() 0 15 2
1
<?php
2
3
namespace BsbDoctrineReconnectTest\Util;
4
5
use Zend\Mvc\Service\ServiceManagerConfig;
6
use Zend\ServiceManager\ServiceManager;
7
8
class ServiceManagerFactory
9
{
10
    /**
11
     * @var array
12
     */
13
    protected static $config;
14
15
    /**
16
     * @param array $config
17
     */
18
    public static function setConfig(array $config)
19
    {
20
        static::$config = $config;
21
    }
22
23
    /**
24
     * Builds a new service manager
25
     */
26
    public static function getServiceManager()
27
    {
28
        $serviceManager = new ServiceManager(new ServiceManagerConfig(
0 ignored issues
show
Documentation introduced by
new \Zend\Mvc\Service\Se...ce_manager'] : array()) is of type object<Zend\Mvc\Service\ServiceManagerConfig>, but the function expects a array.

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...
29
            isset(static::$config['service_manager']) ? static::$config['service_manager'] : []
30
        ));
31
        
32
        $serviceManager->setService('ApplicationConfig', static::$config);
33
        $serviceManager->setFactory('ServiceListener', 'Zend\Mvc\Service\ServiceListenerFactory');
34
35
        /** @var $moduleManager \Zend\ModuleManager\ModuleManager */
36
        $moduleManager = $serviceManager->get('ModuleManager');
37
        $moduleManager->loadModules();
38
39
        return $serviceManager;
40
    }
41
}
42