Completed
Push — master ( 537349...e26b4a )
by Westin
11:04
created

OverflowHandlerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

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