Logger   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 94.12%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 53
ccs 16
cts 17
cp 0.9412
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getChannel() 0 4 1
A log() 0 15 3
1
<?php
2
3
namespace Oqq\Minc\Log;
4
5
use Psr\Log\AbstractLogger;
6
use Psr\Log\InvalidArgumentException;
7
use Oqq\Minc\Log\Handler\HandlerContainerInterface;
8
use Oqq\Minc\Log\Handler\HandlerContainerTrait;
9
use Oqq\Minc\Log\Processor\ProcessorContainerInterface;
10
use Oqq\Minc\Log\Processor\ProcessorContainerTrait;
11
use Oqq\Minc\Log\Handler\HandlerInterface;
12
use Oqq\Minc\Log\Processor\ProcessorInterface;
13
14
/**
15
 * @author Eric Braun <[email protected]>
16
 */
17
class Logger extends AbstractLogger implements LoggerInterface, HandlerContainerInterface, ProcessorContainerInterface
18
{
19
    use HandlerContainerTrait;
20
    use ProcessorContainerTrait;
21
22
    /** @var string */
23
    protected $channel;
24
25
    /**
26
     * @param string $channel
27
     * @param HandlerInterface[] $handlers
28
     * @param ProcessorInterface[] $processors
29
     */
30 14
    public function __construct(
31
        $channel = LoggerInterface::DEFAULT_CHANNEL,
32
        array $handlers = [],
33
        array $processors = []
34
    ) {
35 14
        $this->channel = $channel;
36
37 14
        $this->setHandlers($handlers);
38 14
        $this->setProcessors($processors);
39 14
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 13
    public function getChannel()
45
    {
46 13
        return $this->channel;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @throws InvalidArgumentException
53
     */
54 13
    public function log($levelName, $message, array $context = [])
55
    {
56 13
        $record = new Record($this->getChannel(), (string) $message, Level::createFromName($levelName));
57 12
        $record->setContext($context);
58
59 12
        $this->applyProcessors($record);
60
61 12
        foreach ($this->handlers as $handler) {
62 12
            $pass = $handler->handle($record);
63
64 12
            if (true !== $pass) {
65
                break;
66
            }
67 12
        }
68 12
    }
69
}
70