Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A makeFileLogger() 0 10 2
A __construct() 0 3 1
A makeNullLogger() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DarkMatter\Components\Logger;
6
7
class Factory
8
{
9
    /**
10
     * @var array $config
11
     */
12
    protected $config = [];
13
14
    public function __construct(array $config)
15
    {
16
        $this->config = $config['logger'] ?? [];
17
    }
18
19
    /**
20
     * Creates a new file logger.
21
     *
22
     * @return FileLogger
23
     * @throws LoggerException
24
     */
25
    public function makeFileLogger(): FileLogger
26
    {
27
        if (empty($this->config['path_logs'])) {
28
            throw new LoggerException('Invalid logger config. "path_logs" is missing.');
29
        }
30
        $logger = new FileLogger;
31
        $logger->setLogsDir($this->config['path_logs']);
32
        $logger->setMinLevel($this->config['min_level'] ?? LogLevel::WARNING);
33
34
        return $logger;
35
    }
36
37
    /**
38
     * Creates a new null logger.
39
     *s
40
     * @return NullLogger
41
     */
42
    public function makeNullLogger(): NullLogger
43
    {
44
        return new NullLogger;
45
    }
46
}
47