getActivationStrategy()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11MonoLog\Handler;
6
7
use Monolog\Handler\FingersCrossedHandler;
8
use WShafer\PSR11MonoLog\HandlerManagerAwareInterface;
9
use WShafer\PSR11MonoLog\HandlerManagerTrait;
10
use WShafer\PSR11MonoLog\ContainerAwareInterface;
11
use WShafer\PSR11MonoLog\ContainerTrait;
12
use WShafer\PSR11MonoLog\FactoryInterface;
13
14
class FingersCrossedHandlerFactory implements FactoryInterface, HandlerManagerAwareInterface, ContainerAwareInterface
15
{
16
    use ContainerTrait;
17
    use HandlerManagerTrait;
18
19 3
    public function __invoke(array $options)
20
    {
21 3
        $handler            = $this->getHandlerManager()->get($options['handler']);
22 3
        $activationStrategy = $this->getActivationStrategy($options);
23 3
        $bufferSize         = (int)     ($options['bufferSize']    ?? 0);
24 3
        $bubble             = (bool) ($options['bubble']        ?? true);
25 3
        $stopBuffering      = (bool) ($options['stopBuffering'] ?? true);
26 3
        $passthruLevel      =            $options['passthruLevel'] ?? null;
27
28 3
        return new FingersCrossedHandler(
29 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...
30 3
            $activationStrategy,
31 3
            $bufferSize,
32 3
            $bubble,
33 3
            $stopBuffering,
34 3
            $passthruLevel
35
        );
36
    }
37
38 3
    protected function getActivationStrategy($options)
39
    {
40 3
        $activationStrategy = $options['activationStrategy'] ?? null;
41
42 3
        if (!$activationStrategy) {
43 1
            return null;
44
        }
45
46 2
        if ($this->getContainer()->has($activationStrategy)) {
47 1
            return $this->getContainer()->get($activationStrategy);
48
        }
49
50 1
        return $activationStrategy;
51
    }
52
}
53