FilterAnnotationHandler::read()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
ccs 12
cts 12
cp 1
crap 2
1
<?php
2
namespace Redbox\Hooks\Annotations;
3
4
use Doctrine\Common\Annotations\Reader;
5
use Redbox\Hooks\Filters;
6
7
class FilterAnnotationHandler
8
{
9
    private $reader;
10
    private $annotationClass = 'Redbox\Hooks\Annotations\Filter';
11
12 4
    public function __construct(Reader $reader)
13
    {
14 4
        $this->reader = $reader;
15 4
    }
16
17 4
    public function read($object)
18
    {
19
20
21 4
        $reflectionObject = new \ReflectionObject($object);
22
23 4
        foreach ($reflectionObject->getMethods() as $reflectionMethod) {
24
25
            /**
26
             * Weird but still be need to do this.
27
             */
28 4
            new $this->annotationClass;
29
30
            /**
31
             * Autoload or instantiate the object
32
             */
33 4
            $annotation = $this->reader->getMethodAnnotation($reflectionMethod, $this->annotationClass);
34
35 4
            Filters::addFilter(
36 4
                $annotation->getPropertyName(),
37 4
                [$object, $reflectionMethod->name],
0 ignored issues
show
Documentation introduced by
array($object, $reflectionMethod->name) is of type array<integer,?,{"0":"?","1":"?"}>, but the function expects a string.

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...
38 4
                $annotation->priority
39 2
            );
40 2
        }
41 4
    }
42
}
43