Completed
Push — master ( c54f16...52d0a8 )
by Korotkov
02:09 queued 10s
created

ContainerConfigTrait::addConfig()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @copyright Copyright (c) 2018, Korotkov Danila
8
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
9
 */
10
11
namespace Rudra\Traits;
12
13
/**
14
 * Trait ContainerConfigTrait
15
 * @package Rudra
16
 */
17
trait ContainerConfigTrait
18
{
19
20
    /**
21
     * @var array
22
     */
23
    protected $config = [];
24
25
    /**
26
     * @param string      $key
27
     * @param string|null $subKey
28
     * @return mixed
29
     */
30
    public function config(string $key, string $subKey = null)
31
    {
32
        return ($subKey === null) ? $this->config[$key] : $this->config[$key][$subKey];
33
    }
34
35
    /**
36
     * @param array $config
37
     */
38
    public function setConfig(array $config): void
39
    {
40
        $this->config = $config;
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    public function getConfig(): array
47
    {
48
        return $this->config;
49
    }
50
51
    /**
52
     * @param $key
53
     * @param $value
54
     */
55
    public function addConfig($key, $value): void
56
    {
57
        if (is_array($key) && array_key_exists(1, $key)) {
58
            $this->config[$key[0]][$key[1]] = $value;
59
            return;
60
        }
61
62
        $this->config[$key] = $value;
63
    }
64
}
65