Completed
Pull Request — master (#40)
by Marko
116:46 queued 51:48
created

ConfigManager   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 107
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 FOS\CKEditorBundle\Model;
13
14
use FOS\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
    public function __construct(array $configs = [], $defaultConfig = null)
36
    {
37
        $this->setConfigs($configs);
38
39
        if ($defaultConfig !== null) {
40
            $this->setDefaultConfig($defaultConfig);
41
        }
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getDefaultConfig()
48
    {
49
        return $this->defaultConfig;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function setDefaultConfig($defaultConfig)
56
    {
57
        if (!$this->hasConfig($defaultConfig)) {
58
            throw ConfigManagerException::configDoesNotExist($defaultConfig);
59
        }
60
61
        $this->defaultConfig = $defaultConfig;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function hasConfigs()
68
    {
69
        return !empty($this->configs);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function getConfigs()
76
    {
77
        return $this->configs;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83
    public function setConfigs(array $configs)
84
    {
85
        foreach ($configs as $name => $config) {
86
            $this->setConfig($name, $config);
87
        }
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function hasConfig($name)
94
    {
95
        return isset($this->configs[$name]);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function getConfig($name)
102
    {
103
        if (!$this->hasConfig($name)) {
104
            throw ConfigManagerException::configDoesNotExist($name);
105
        }
106
107
        return $this->configs[$name];
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function setConfig($name, array $config)
114
    {
115
        $this->configs[$name] = $config;
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function mergeConfig($name, array $config)
122
    {
123
        $this->configs[$name] = array_merge($this->getConfig($name), $config);
124
    }
125
}
126