SamplingHandlerFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 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