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

FingersCrossedHandlerFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 39
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 18 1
A getActivationStrategy() 0 14 3
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11MonoLog\Handler;
5
6
use Monolog\Handler\FingersCrossedHandler;
7
use WShafer\PSR11MonoLog\HandlerManagerAwareInterface;
8
use WShafer\PSR11MonoLog\HandlerManagerTrait;
9
use WShafer\PSR11MonoLog\ContainerAwareInterface;
10
use WShafer\PSR11MonoLog\ContainerTrait;
11
use WShafer\PSR11MonoLog\FactoryInterface;
12
13
class FingersCrossedHandlerFactory implements FactoryInterface, HandlerManagerAwareInterface, ContainerAwareInterface
14
{
15
    use ContainerTrait;
16
    use HandlerManagerTrait;
17
18 3
    public function __invoke(array $options)
19
    {
20 3
        $handler            = $this->getHandlerManager()->get($options['handler']);
21 3
        $activationStrategy = $this->getActivationStrategy($options);
22 3
        $bufferSize         = (int)     ($options['bufferSize']    ?? 0);
23 3
        $bubble             = (boolean) ($options['bubble']        ?? true);
24 3
        $stopBuffering      = (boolean) ($options['stopBuffering'] ?? true);
25 3
        $passthruLevel      =            $options['passthruLevel'] ?? null;
26
27 3
        return new FingersCrossedHandler(
28 3
            $handler,
0 ignored issues
show
Documentation introduced by
$handler is of type *, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29 3
            $activationStrategy,
30 3
            $bufferSize,
31 3
            $bubble,
32 3
            $stopBuffering,
33 3
            $passthruLevel
34
        );
35
    }
36
37 3
    protected function getActivationStrategy($options)
38
    {
39 3
        $activationStrategy = $options['activationStrategy'] ?? null;
40
41 3
        if (!$activationStrategy) {
42 1
            return null;
43
        }
44
45 2
        if ($this->getContainer()->has($activationStrategy)) {
46 1
            return $this->getContainer()->get($activationStrategy);
47
        }
48
49 1
        return $activationStrategy;
50
    }
51
}
52