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

ConfigContainer::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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