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

ConfigTrait::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
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