ConfigManager   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 107
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getDefaultConfig() 0 4 1
A setDefaultConfig() 0 8 2
A hasConfigs() 0 4 1
A getConfigs() 0 4 1
A setConfigs() 0 6 2
A hasConfig() 0 4 1
A getConfig() 0 8 2
A setConfig() 0 4 1
A mergeConfig() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory CKEditor package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\CKEditorBundle\Model;
13
14
use Ivory\CKEditorBundle\Exception\ConfigManagerException;
15
16
/**
17
 * @author GeLo <[email protected]>
18
 */
19
class ConfigManager implements ConfigManagerInterface
20
{
21
    /**
22
     * @var string
23
     */
24
    private $defaultConfig;
25
26
    /**
27
     * @var array
28
     */
29
    private $configs = [];
30
31
    /**
32
     * @param array       $configs
33
     * @param string|null $defaultConfig
34
     */
35 230
    public function __construct(array $configs = [], $defaultConfig = null)
36
    {
37 230
        $this->setConfigs($configs);
38
39 230
        if ($defaultConfig !== null) {
40 10
            $this->setDefaultConfig($defaultConfig);
41 8
        }
42 230
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 60
    public function getDefaultConfig()
48
    {
49 60
        return $this->defaultConfig;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 60
    public function setDefaultConfig($defaultConfig)
56
    {
57 60
        if (!$this->hasConfig($defaultConfig)) {
58 10
            throw ConfigManagerException::configDoesNotExist($defaultConfig);
59
        }
60
61 50
        $this->defaultConfig = $defaultConfig;
62 50
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 20
    public function hasConfigs()
68
    {
69 20
        return !empty($this->configs);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 50
    public function getConfigs()
76
    {
77 50
        return $this->configs;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 230
    public function setConfigs(array $configs)
84
    {
85 230
        foreach ($configs as $name => $config) {
86 40
            $this->setConfig($name, $config);
87 184
        }
88 230
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93 100
    public function hasConfig($name)
94
    {
95 100
        return isset($this->configs[$name]);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101 40
    public function getConfig($name)
102
    {
103 40
        if (!$this->hasConfig($name)) {
104 20
            throw ConfigManagerException::configDoesNotExist($name);
105
        }
106
107 20
        return $this->configs[$name];
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113 70
    public function setConfig($name, array $config)
114
    {
115 70
        $this->configs[$name] = $config;
116 70
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121 20
    public function mergeConfig($name, array $config)
122
    {
123 20
        $this->configs[$name] = array_merge($this->getConfig($name), $config);
124 10
    }
125
}
126