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

ConfigTrait::getDefaultConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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