Completed
Push — master ( bfa80e...3adc88 )
by Alexander
02:11
created

OrPointcut::matches()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 0
cts 0
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 4
crap 6
1
<?php
2
declare(strict_types = 1);
3
/*
4
 * Go! AOP framework
5
 *
6
 * @copyright Copyright 2013, Lisachenko Alexander <[email protected]>
7
 *
8
 * This source file is subject to the license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Go\Aop\Pointcut;
13
14
use Go\Aop\Pointcut;
15
use Go\Aop\PointFilter;
16
use Go\Aop\Support\OrPointFilter;
17
18
/**
19
 * Signature method pointcut checks method signature (modifiers and name) to match it
20
 */
21
class OrPointcut extends AndPointcut
22
{
23
24
    /**
25
     * Signature method matcher constructor
26
     *
27
     * @param Pointcut $first First filter
28
     * @param Pointcut $second Second filter
29
     */
30 2
    public function __construct(Pointcut $first, Pointcut $second)
31
    {
32 2
        $this->first  = $first;
33 2
        $this->second = $second;
34 2
        $this->kind   = $first->getKind() | $second->getKind();
35
36 2
        $this->classFilter = new OrPointFilter($first->getClassFilter(), $second->getClassFilter());
37 2
    }
38
39
    /**
40
     * Performs matching of point of code
41
     *
42
     * @param mixed $point Specific part of code, can be any Reflection class
43
     * @param null|mixed $context Related context, can be class or namespace
44
     * @param null|string|object $instance Invocation instance or string for static calls
45
     * @param null|array $arguments Dynamic arguments for method
46
     *
47
     * @return bool
48
     */
49
    public function matches($point, $context = null, $instance = null, array $arguments = null) : bool
50
    {
51
        return $this->matchPart($this->first, $point, $context, $instance, $arguments)
52
            || $this->matchPart($this->second, $point, $context, $instance, $arguments);
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    protected function matchPart(Pointcut $pointcut, $point, $context = null, $instance = null, array $arguments = null)
59
    {
60
        $pointcutKind = $pointcut->getKind();
61
        // We need to recheck filter kind one more time, because of OR syntax
62
        switch (true) {
63
            case ($point instanceof \ReflectionMethod && ($pointcutKind & PointFilter::KIND_METHOD)):
64
            case ($point instanceof \ReflectionProperty && ($pointcutKind & PointFilter::KIND_PROPERTY)):
65
            case ($point instanceof \ReflectionClass && ($pointcutKind & PointFilter::KIND_CLASS)):
66
                return parent::matchPart($pointcut, $point, $context, $instance, $arguments);
0 ignored issues
show
Bug introduced by
It seems like $point can also be of type object<ReflectionClass>; however, Go\Aop\Pointcut\AndPointcut::matchPart() does only seem to accept object<ReflectionMethod>...ect<ReflectionProperty>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67
68
            default:
69
                return false;
70
        }
71
    }
72
}
73