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

OverflowHandlerFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 24 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