Completed
Push — master ( a0bca0...91676c )
by Alexander
02:32
created

MatchInheritedPointcut::matches()   A

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