Passed
Push — master ( 4f923e...f2cf92 )
by 世昌
01:48
created

ConfigTrait::applyConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\component\debug;
3
4
trait ConfigTrait
5
{
6
    
7
    /**
8
     * 配置信息
9
     *
10
     * @var array
11
     */
12
    protected $config;
13
14
    public function applyConfig(array $config)
15
    {
16
        $defaultConfig = $this->getDefaultConfig();
17
        foreach ($defaultConfig as $name => $value) {
18
            $this->config[$name] = $config[$name] ?? $this->config[$name] ?? $value;
19
        }
20
    }
21
    public function getConfig(string $name, $default =null) {
22
        $defaultConfig = $this->getDefaultConfig();
23
        return $this->config[$name] ?? $defaultConfig[$name] ?? $default;
24
    }
25
26
    abstract public function getDefaultConfig():array;
27
}
28