SamplingHandlerFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 9
cp 1
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11MonoLog\Handler;
6
7
use Monolog\Handler\SamplingHandler;
8
use WShafer\PSR11MonoLog\Exception\InvalidConfigException;
9
use WShafer\PSR11MonoLog\HandlerManagerAwareInterface;
10
use WShafer\PSR11MonoLog\HandlerManagerTrait;
11
use WShafer\PSR11MonoLog\FactoryInterface;
12
13
class SamplingHandlerFactory implements FactoryInterface, HandlerManagerAwareInterface
14
{
15
    use HandlerManagerTrait;
16
17 2
    public function __invoke(array $options)
18
    {
19 2
        $handler = $this->getHandlerManager()->get($options['handler']);
20 2
        $factor  = (int) ($options['factor'] ?? null);
21
22 2
        if (empty($factor)) {
23 1
            throw new InvalidConfigException(
24 1
                'Factor is missing or is less then 1'
25
            );
26
        }
27
28 1
        return new SamplingHandler(
29 1
            $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 1
            $factor
31
        );
32
    }
33
}
34