Completed
Push — master ( 111bcd...99ca87 )
by Andrey
26:30
created

JmsSerializerModuleServiceManagerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 14 4
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/jms-serializer-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\JmsSerializerModule\ModuleServiceManager;
7
8
use Zend\ServiceManager\FactoryInterface;
9
use Zend\ServiceManager\ServiceLocatorInterface;
10
use Zend\ServiceManager\Config;
11
use Nnx\JmsSerializerModule\Module;
12
13
14
/**
15
 * Class JmsSerializerModuleServiceManagerFactory
16
 *
17
 * @package Nnx\JmsSerializerModule\ModuleServiceManager
18
 */
19
class JmsSerializerModuleServiceManagerFactory implements FactoryInterface
20
{
21
22
    /**
23
     * @param ServiceLocatorInterface $serviceLocator
24
     *
25
     * @return JmsSerializerModuleServiceManager
26
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
27
     */
28
    public function createService(ServiceLocatorInterface $serviceLocator)
29
    {
30
        $appConfig = $serviceLocator->get('config');
31
        $isModuleConfig =
32
            is_array($appConfig)
33
            && array_key_exists(Module::MODULE_SERVICE_MANAGER_CONFIG_KEY, $appConfig)
34
            && is_array($appConfig[Module::MODULE_SERVICE_MANAGER_CONFIG_KEY]);
35
        $moduleServiceManagerConfig = $isModuleConfig ? $appConfig[Module::MODULE_SERVICE_MANAGER_CONFIG_KEY] : [];
36
37
        $configuration = new Config($moduleServiceManagerConfig);
38
        $jmsSerializerModuleServiceManager = new JmsSerializerModuleServiceManager($configuration);
39
        $jmsSerializerModuleServiceManager->setServiceLocator($serviceLocator);
40
        return $jmsSerializerModuleServiceManager;
41
    }
42
}
43