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

SamplingHandlerFactory   A

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
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