Completed
Push — 1.x ( 637573...01cf08 )
by Alexander
9s
created

MatchInheritedPointcut::getKind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2016, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Aop\Pointcut;
12
13
use Go\Aop\Pointcut;
14
use Go\Aop\PointFilter;
15
16
/**
17
 * Pointcut that matches all inherited items, this is useful to filter inherited memebers via !matchInherited()
18
 */
19
class MatchInheritedPointcut implements Pointcut
20
{
21
    use PointcutClassFilterTrait;
22
23
    /**
24
     * Performs matching of point of code
25
     *
26
     * @param mixed $point Specific part of code, can be any Reflection class
27
     * @param null|mixed $context Related context, can be class or namespace
28
     * @param null|string|object $instance Invocation instance or string for static calls
29
     * @param null|array $arguments Dynamic arguments for method
30
     *
31
     * @return bool
32
     */
33
    public function matches($point, $context = null, $instance = null, array $arguments = null)
34
    {
35
        if (!$context instanceof \ReflectionClass) {
36
            return false;
37
        };
38
39
        if (!($point instanceof \ReflectionMethod) && !($point instanceof \ReflectionProperty)) {
40
            return false;
41
        }
42
43
        $declaringClassName = $point->getDeclaringClass()->name;
44
45
        return $context->isSubclassOf($declaringClassName);
46
    }
47
48
    /**
49
     * Returns the kind of point filter
50
     *
51
     * @return integer
52
     */
53 1
    public function getKind()
54
    {
55 1
        return PointFilter::KIND_METHOD | PointFilter::KIND_PROPERTY;
56
    }
57
}
58