ModuleOptionsFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createService() 0 10 4
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDebug/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2018 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDebug\Factory;
11
12
use WebinoDebug\Options\ModuleOptions;
13
use Zend\ServiceManager\FactoryInterface;
14
use Zend\ServiceManager\ServiceLocatorInterface;
15
use Zend\Stdlib\ArrayUtils;
16
17
/**
18
 * Factory for module options
19
 */
20
class ModuleOptionsFactory implements FactoryInterface
21
{
22
    /**
23
     * Module options service name
24
     * @deprecated use \WebinoDebug\Options\ModuleOptions::class instead
25
     */
26
    const SERVICE = ModuleOptions::class;
27
28
    /**
29
     * Configuration service section key
30
     */
31
    const CONFIG_KEY = 'webino_debug';
32
33
    /**
34
     * @param ServiceLocatorInterface $services
35
     * @return ModuleOptions
36
     */
37
    public function createService(ServiceLocatorInterface $services)
38
    {
39
        $appConfig = $services->get('ApplicationConfig');
40
        $config = $services->has('Config') ? $services->get('Config') : [];
41
        $options = ArrayUtils::merge(
42
            !empty($appConfig[$this::CONFIG_KEY]) ? $appConfig[$this::CONFIG_KEY] : [],
43
            !empty($config[$this::CONFIG_KEY]) ? $config[$this::CONFIG_KEY] : []
44
        );
45
        return new ModuleOptions($options);
46
    }
47
}
48