ServiceManagerFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfiguration() 0 4 1
A getServiceManager() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest;
6
7
use Laminas\ModuleManager\ModuleManagerInterface;
8
use Laminas\Mvc\Service\ServiceManagerConfig;
9
use Laminas\ServiceManager\ServiceManager;
10
use function assert;
11
12
/**
13
 * Base test case to be used when a service manager instance is required
14
 */
15
class ServiceManagerFactory
16
{
17
    /**
18
     * @return mixed[]
19
     */
20
    public static function getConfiguration() : array
21
    {
22
        return include __DIR__ . '/../TestConfiguration.php';
23
    }
24
25
    /**
26
     * Retrieves a new ServiceManager instance
27
     *
28
     * @param mixed[]|null $configuration
29
     */
30
    public static function getServiceManager(?array $configuration = null) : ServiceManager
31
    {
32
        $configuration        = $configuration ?: static::getConfiguration();
33
        $serviceManager       = new ServiceManager();
34
        $serviceManagerConfig = new ServiceManagerConfig($configuration['service_manager'] ?? []);
35
        $serviceManagerConfig->configureServiceManager($serviceManager);
36
37
        $serviceManager->setService('ApplicationConfig', $configuration);
38
        if (! $serviceManager->has('ServiceListener')) {
39
            $serviceManager->setFactory('ServiceListener', 'Laminas\Mvc\Service\ServiceListenerFactory');
40
        }
41
42
        $moduleManager = $serviceManager->get('ModuleManager');
43
        assert($moduleManager instanceof ModuleManagerInterface);
44
        $moduleManager->loadModules();
45
46
        return $serviceManager;
47
    }
48
}
49