Passed
Pull Request — master (#993)
by Maxim
20:44 queued 10:42
created

EventHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 25
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Monolog;
6
7
use Monolog\Handler\AbstractHandler;
8
use Monolog\Logger;
9
use Spiral\Logger\Event\LogEvent;
10
use Spiral\Logger\ListenerRegistryInterface;
11
12
final class EventHandler extends AbstractHandler
13
{
14 21
    public function __construct(
15
        private readonly ListenerRegistryInterface $listenerRegistry,
16
        int $level = Logger::DEBUG,
17
        bool $bubble = true
18
    ) {
19 21
        parent::__construct($level, $bubble);
20
    }
21
22 2
    public function handle(array $record): bool
23
    {
24 2
        $e = new LogEvent(
25 2
            $record['datetime'],
26 2
            $record['channel'],
27 2
            \strtolower(Logger::getLevelName($record['level'])),
28 2
            $record['message'],
29 2
            $record['context']
30 2
        );
31
32 2
        foreach ($this->listenerRegistry->getListeners() as $listener) {
33 2
            $listener($e);
34
        }
35
36 2
        return true;
37
    }
38
}
39