Test Failed
Push — dev ( 9afba2...a28fc9 )
by 世昌
02:21
created

ConfigTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 39
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A applyConfig() 0 5 2
A getConfig() 0 4 1
A getDefaultConfig() 0 10 1
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
    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
22
    public function getConfig(string $name)
23
    {
24
        $defaultConfig = $this->getDefaultConfig();
25
        return $this->config[$name] ?? $defaultConfig[$name];
26
    }
27
28
    abstract public function getDefaultConfig():array;
29
30
    /**
31
     * @return array
32
     */
33
    public function getDefaultConfig(): array
34
    {
35
        return [
36
            'save-path' => './logs',
37
            'save-zip-path' => './logs/zip',
38
            'save-dump-path' => './logs/dump',
39
            'max-file-size' => 2097152,
40
            'file-name' => 'latest.log',
41
            'log-level' => 'debug',
42
            'log-format' => '[%level%] %message%',
43
        ];
44
    }
45
}
46