Passed
Pull Request — master (#1124)
by
unknown
03:55 queued 01:03
created

LoggerConfig::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Config;
6
7
class LoggerConfig implements ConfigInterface
8
{
9
    public function __construct(
10
        public bool $enable = false,
11
        public string $file = './logs/pay.log',
12
        public string $level = 'info',
13
        public string $type = 'single',
14
        public int $max_file = 30,
15
    ) {
16
    }
17
18
    public function toArray(): array
19
    {
20
        return [
21
            'enable' => $this->enable,
22
            'file' => $this->file,
23
            'level' => $this->level,
24
            'type' => $this->type,
25
            'max_file' => $this->max_file,
26
        ];
27
    }
28
29
    public static function fromArray(array $config): self
30
    {
31
        return new self(
32
            enable: $config['enable'] ?? false,
33
            file: $config['file'] ?? './logs/pay.log',
34
            level: $config['level'] ?? 'info',
35
            type: $config['type'] ?? 'single',
36
            max_file: $config['max_file'] ?? 30,
37
        );
38
    }
39
}
40