Completed
Push — master ( 20dd79...fbc01c )
by Westin
04:56 queued 03:09
created

GroupHandlerFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11MonoLog\Handler;
5
6
use Monolog\Handler\GroupHandler;
7
use WShafer\PSR11MonoLog\Exception\MissingConfigException;
8
use WShafer\PSR11MonoLog\HandlerManagerAwareInterface;
9
use WShafer\PSR11MonoLog\HandlerManagerTrait;
10
use WShafer\PSR11MonoLog\FactoryInterface;
11
12
class GroupHandlerFactory implements FactoryInterface, HandlerManagerAwareInterface
13
{
14
    use HandlerManagerTrait;
15
16 3 View Code Duplication
    public function __invoke(array $options)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18 3
        $handlers = $this->getHandlers($options);
19 1
        $bubble   = (boolean) ($options['bubble'] ?? true);
20
21 1
        return new GroupHandler(
22 1
            $handlers,
23 1
            $bubble
24
        );
25
    }
26
27 3
    protected function getHandlers($options)
28
    {
29 3
        $handlers = $options['handlers'] ?? [];
30
31 3
        if (empty($handlers) || !is_array($handlers)) {
32 2
            throw new MissingConfigException(
33 2
                "No handlers specified"
34
            );
35
        }
36
37 1
        $return = [];
38
39 1
        foreach ($handlers as $handler) {
40 1
            $return[] = $this->getHandlerManager()->get($handler);
41
        }
42
43 1
        return $return;
44
    }
45
}
46