Completed
Push — 1.x ( e02265...501840 )
by Alexander
02:28
created

OrPointcut::matchPart()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 8.2222
cc 7
eloc 9
nc 4
nop 5
crap 56
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2013, 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
use Go\Aop\Support\OrPointFilter;
16
use TokenReflection\ReflectionClass;
17
use TokenReflection\ReflectionMethod;
18
use TokenReflection\ReflectionProperty;
19
20
/**
21
 * Signature method pointcut checks method signature (modifiers and name) to match it
22
 */
23
class OrPointcut extends AndPointcut
24
{
25
26
    /**
27
     * Signature method matcher constructor
28
     *
29
     * @param Pointcut $first First filter
30
     * @param Pointcut $second Second filter
31
     */
32 2
    public function __construct(Pointcut $first, Pointcut $second)
33
    {
34 2
        $this->first  = $first;
35 2
        $this->second = $second;
36 2
        $this->kind   = $first->getKind() | $second->getKind();
37
38 2
        $this->classFilter = new OrPointFilter($first->getClassFilter(), $second->getClassFilter());
39 2
    }
40
41
    /**
42
     * Performs matching of point of code
43
     *
44
     * @param mixed $point Specific part of code, can be any Reflection class
45
     * @param null|mixed $context Related context, can be class or namespace
46
     * @param null|string|object $instance Invocation instance or string for static calls
47
     * @param null|array $arguments Dynamic arguments for method
48
     *
49
     * @return bool
50
     */
51
    public function matches($point, $context = null, $instance = null, array $arguments = null)
52
    {
53
        return $this->matchPart($this->first, $point, $context, $instance, $arguments)
54
            || $this->matchPart($this->second, $point, $context, $instance, $arguments);
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    protected function matchPart(Pointcut $pointcut, $point, $context = null, $instance = null, array $arguments = null)
61
    {
62
        $pointcutKind = $pointcut->getKind();
63
        // We need to recheck filter kind one more time, because of OR syntax
64
        switch (true) {
65
            case ($point instanceof ReflectionMethod && ($pointcutKind & PointFilter::KIND_METHOD)):
0 ignored issues
show
Bug introduced by
The class TokenReflection\ReflectionMethod does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
66
            case ($point instanceof ReflectionProperty && ($pointcutKind & PointFilter::KIND_PROPERTY)):
0 ignored issues
show
Bug introduced by
The class TokenReflection\ReflectionProperty does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
67
            case ($point instanceof ReflectionClass && ($pointcutKind & PointFilter::KIND_CLASS)):
0 ignored issues
show
Bug introduced by
The class TokenReflection\ReflectionClass does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
68
                return parent::matchPart($pointcut, $point, $context, $instance, $arguments);
69
70
            default:
71
                return false;
72
        }
73
    }
74
}
75