Completed
Pull Request — master (#463)
by Alexander
30:17 queued 05:15
created

AndPointcut   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 75
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * Go! AOP framework
6
 *
7
 * @copyright Copyright 2013, Lisachenko Alexander <[email protected]>
8
 *
9
 * This source file is subject to the license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Go\Aop\Pointcut;
14
15
use Go\Aop\Pointcut;
16
use Go\Aop\Support\AndPointFilter;
17
use ReflectionMethod;
18
use ReflectionProperty;
19
20
/**
21
 * Logical "AND" pointcut that combines two simple pointcuts
22
 */
23
class AndPointcut implements Pointcut
24
{
25
    use PointcutClassFilterTrait;
26
27
    /**
28
     * First pointcut
29
     */
30
    protected Pointcut $first;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
31
32
    /**
33
     * Second pointcut
34
     */
35
    protected Pointcut $second;
36
37
    /**
38
     * Returns pointcut kind
39
     */
40
    protected int $kind;
41
42 3
    /**
43
     * "And" pointcut constructor
44 3
     */
45 3
    public function __construct(Pointcut $first, Pointcut $second)
46 3
    {
47
        $this->first  = $first;
48 3
        $this->second = $second;
49 3
        $this->kind   = $first->getKind() & $second->getKind();
50
51
        $this->classFilter = new AndPointFilter($first->getClassFilter(), $second->getClassFilter());
52
    }
53
54
    /**
55
     * Performs matching of point of code
56
     *
57
     * @param mixed              $point     Specific part of code, can be any Reflection class
58
     * @param null|mixed         $context   Related context, can be class or namespace
59
     * @param null|string|object $instance  Invocation instance or string for static calls
60
     * @param null|array         $arguments Dynamic arguments for method
61
     */
62
    public function matches($point, $context = null, $instance = null, array $arguments = null): bool
63
    {
64
        return $this->matchPart($this->first, $point, $context, $instance, $arguments)
65
            && $this->matchPart($this->second, $point, $context, $instance, $arguments);
66
    }
67
68 2
    /**
69
     * Returns the kind of point filter
70 2
     */
71
    public function getKind(): int
72
    {
73
        return $this->kind;
74
    }
75
76
    /**
77
     * Checks if point filter matches the point
78
     *
79
     * @param Pointcut                            $pointcut
80
     * @param ReflectionMethod|ReflectionProperty $point
81
     * @param mixed                               $context   Related context, can be class or namespace
82
     * @param object|string|null                  $instance  [Optional] Instance for dynamic matching
83
     * @param array|null                          $arguments [Optional] Extra arguments for dynamic matching
84 1
     *
85
     * @return bool
86
     */
87
    protected function matchPart(
88
        Pointcut $pointcut,
89
        $point,
90
        $context = null,
91 1
        $instance = null,
92 1
        array $arguments = null
93
    ): bool {
94
        return $pointcut->matches($point, $context, $instance, $arguments)
95
            && $pointcut->getClassFilter()->matches($context);
96
    }
97
}
98