Passed
Push — master ( 79eb06...102376 )
by 世昌
02:35
created

ConfigTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 3 1
A getConfig() 0 4 1
A applyConfig() 0 5 2
1
<?php
2
namespace suda\framework\debug;
3
4
trait ConfigTrait
5
{
6
    
7
    /**
8
     * 配置信息
9
     *
10
     * @var array
11
     */
12
    protected $config;
13
14
    /**
15
     * @param array $config
16
     */
17
    public function applyConfig(array $config)
18
    {
19
        $defaultConfig = $this->getDefaultConfig();
20
        foreach ($defaultConfig as $name => $value) {
21
            $this->config[$name] = $config[$name] ?? $this->config[$name] ?? $value;
22
        }
23
    }
24
25
    /**
26
     * @param string $name
27
     * @param $value
28
     */
29
    public function setConfig(string $name, $value)
30
    {
31
        $this->config[$name] = $value;
32
    }
33
34
    /**
35
     * @param string $name
36
     * @return mixed
37
     */
38
    public function getConfig(string $name)
39
    {
40
        $defaultConfig = $this->getDefaultConfig();
41
        return $this->config[$name] ?? $defaultConfig[$name];
42
    }
43
44
    abstract public function getDefaultConfig():array;
45
}
46