OverflowHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 17
cts 17
cp 1
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11MonoLog\Handler;
6
7
use Monolog\Handler\OverflowHandler;
8
use Monolog\Logger;
9
use WShafer\PSR11MonoLog\HandlerManagerAwareInterface;
10
use WShafer\PSR11MonoLog\HandlerManagerTrait;
11
use WShafer\PSR11MonoLog\FactoryInterface;
12
13
class OverflowHandlerFactory implements FactoryInterface, HandlerManagerAwareInterface
14
{
15
    use HandlerManagerTrait;
16
17 2
    public function __invoke(array $options)
18
    {
19 2
        $handler = $this->getHandlerManager()->get($options['handler']);
20
        $thresholdMap = [
21 1
            Logger::DEBUG => $options['thresholdMap']['debug'] ?? 0,
22 1
            Logger::INFO => $options['thresholdMap']['info'] ?? 0,
23 1
            Logger::NOTICE => $options['thresholdMap']['notice'] ?? 0,
24 1
            Logger::WARNING => $options['thresholdMap']['warning'] ?? 0,
25 1
            Logger::ERROR => $options['thresholdMap']['error'] ?? 0,
26 1
            Logger::CRITICAL => $options['thresholdMap']['critical'] ?? 0,
27 1
            Logger::ALERT => $options['thresholdMap']['alert'] ?? 0,
28 1
            Logger::EMERGENCY => $options['thresholdMap']['emergency'] ?? 0,
29
        ];
30
31 1
        $level  = (int)     ($options['level']  ?? Logger::DEBUG);
32 1
        $bubble = (bool) ($options['bubble'] ?? true);
33
34 1
        return new OverflowHandler(
35 1
            $handler,
36 1
            $thresholdMap,
37 1
            $level,
38 1
            $bubble
39
        );
40
    }
41
}
42