GroupHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.9332
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\GroupHandler;
8
use WShafer\PSR11MonoLog\Exception\MissingConfigException;
9
use WShafer\PSR11MonoLog\HandlerManagerAwareInterface;
10
use WShafer\PSR11MonoLog\HandlerManagerTrait;
11
use WShafer\PSR11MonoLog\FactoryInterface;
12
13
class GroupHandlerFactory implements FactoryInterface, HandlerManagerAwareInterface
14
{
15
    use HandlerManagerTrait;
16
17 3
    public function __invoke(array $options)
18
    {
19 3
        $handlers = $this->getHandlers($options);
20 1
        $bubble   = (bool) ($options['bubble'] ?? true);
21
22 1
        return new GroupHandler(
23 1
            $handlers,
24 1
            $bubble
25
        );
26
    }
27
28 3
    protected function getHandlers($options)
29
    {
30 3
        $handlers = $options['handlers'] ?? [];
31
32 3
        if (empty($handlers) || !is_array($handlers)) {
33 2
            throw new MissingConfigException(
34 2
                "No handlers specified"
35
            );
36
        }
37
38 1
        $return = [];
39
40 1
        foreach ($handlers as $handler) {
41 1
            $return[] = $this->getHandlerManager()->get($handler);
42
        }
43
44 1
        return $return;
45
    }
46
}
47