Completed
Push — master ( b7f544...05e48a )
by Mike
05:04
created

ConfigContainer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 3 1
A set() 0 5 1
A get() 0 6 2
A toArray() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Config\Business\Container;
6
7
8
class ConfigContainer
9
{
10
    /**
11
     * @var array
12
     */
13
    private $configs = [];
14
15
    /**
16
     * @param string $name
17
     * @param mixed $val
18
     *
19
     * @return \Xervice\Config\Business\Container\ConfigContainer
20
     */
21 10
    public function set(string $name, $val): ConfigContainer
22
    {
23 10
        $this->configs[$name] = $val;
24
25 10
        return $this;
26
    }
27
28
    /**
29
     * @param array $config
30
     */
31 8
    public function fromArray(array $config): void
32
    {
33 8
        $this->configs = array_merge($this->configs, $config);
34 8
    }
35
36
    /**
37
     * @return array
38
     */
39 8
    public function toArray(): array
40
    {
41 8
        return $this->configs;
42
    }
43
44
    /**
45
     * @param string $name
46
     * @param mixed $default
47
     *
48
     * @return mixed
49
     */
50 10
    public function get(string $name, $default = null)
51
    {
52 10
        if (!isset($this->configs[$name])) {
53 4
            $this->set($name, $default);
54
        }
55 10
        return $this->configs[$name];
56
    }
57
}
58