FilterAnnotationHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B read() 0 25 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