MatchInheritedPointcut::matches()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 16
c 0
b 0
f 0
ccs 0
cts 8
cp 0
rs 9.4222
cc 5
nc 4
nop 4
crap 30
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * Go! AOP framework
6
 *
7
 * @copyright Copyright 2016, 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\PointFilter;
17
use ReflectionClass;
18
use ReflectionMethod;
19
use ReflectionProperty;
20
21
/**
22
 * Pointcut that matches all inherited items, this is useful to filter inherited memebers via !matchInherited()
23
 */
24
class MatchInheritedPointcut implements Pointcut
0 ignored issues
show
Bug introduced by
There is one abstract method getClassFilter in this class; you could implement it, or declare this class as abstract.
Loading history...
25
{
26
    use PointcutClassFilterTrait;
27
28
    /**
29
     * Performs matching of point of code
30
     *
31
     * @param mixed              $point     Specific part of code, can be any Reflection class
32
     * @param null|mixed         $context   Related context, can be class or namespace
33
     * @param null|string|object $instance  Invocation instance or string for static calls
34
     * @param null|array         $arguments Dynamic arguments for method
35
     */
36
    public function matches($point, $context = null, $instance = null, array $arguments = null): bool
37
    {
38
        if (!$context instanceof ReflectionClass) {
39
            return false;
40
        }
41
42
        $isPointMethod   = $point instanceof ReflectionMethod;
43
        $isPointProperty = $point instanceof ReflectionProperty;
44
        if (!$isPointMethod && !$isPointProperty) {
45
            return false;
46
        }
47
48
        $declaringClassName = $point->getDeclaringClass()->name;
49
50
        return $context->name !== $declaringClassName && $context->isSubclassOf($declaringClassName);
51
    }
52
53
    /**
54
     * Returns the kind of point filter
55 1
     */
56
    public function getKind(): int
57 1
    {
58
        return PointFilter::KIND_METHOD | PointFilter::KIND_PROPERTY;
59
    }
60
}
61