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

LoggerConfig   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 8 1
A __construct() 0 7 1
A toArray() 0 8 1
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