Completed
Push — master ( fbc01c...6057b3 )
by Westin
15s
created

SamplingHandlerFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

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