Completed
Pull Request — master (#328)
by Nikola
03:49
created

DefaultPointcutAdvisor::getAdvice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 7
cp 0.5714
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 2.3149
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2012, 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\Support;
12
13
use Go\Aop\Advice;
14
use Go\Aop\Framework\DynamicInvocationMatcherInterceptor;
15
use Go\Aop\Pointcut;
16
use Go\Aop\PointFilter;
17
18
/**
19
 * Convenient Pointcut-driven Advisor implementation.
20
 *
21
 * This is the most commonly used Advisor implementation. It can be used with any pointcut and advice type,
22
 * except for introductions. There is normally no need to subclass this class, or to implement custom Advisors.
23
 */
24
class DefaultPointcutAdvisor extends AbstractGenericPointcutAdvisor
25
{
26
27
    /**
28
     * Pointcut instance
29
     *
30
     * @var Pointcut
31
     */
32
    private $pointcut;
33
34
    /**
35
     * Create a DefaultPointcutAdvisor, specifying Pointcut and Advice.
36
     *
37
     * @param Pointcut $pointcut The Pointcut targeting the Advice
38
     * @param Advice $advice The Advice to run when Pointcut matches
39
     */
40 2
    public function __construct(Pointcut $pointcut, Advice $advice)
41
    {
42 2
        $this->pointcut = $pointcut;
43 2
        parent::__construct($advice);
44 2
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 2
    public function getAdvice()
50
    {
51 2
        $advice = parent::getAdvice();
52 2
        if ($this->pointcut->getKind() & PointFilter::KIND_DYNAMIC) {
53
            $advice = new DynamicInvocationMatcherInterceptor(
54
                $this->pointcut,
55
                $advice
0 ignored issues
show
Documentation introduced by
$advice is of type object<Go\Aop\Advice>|null, but the function expects a object<Go\Aop\Intercept\Interceptor>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
            );
57
        }
58
59 2
        return $advice;
60
    }
61
62
63
    /**
64
     * Get the Pointcut that drives this advisor.
65
     *
66
     * @return Pointcut The pointcut
67
     */
68 2
    public function getPointcut()
69
    {
70 2
        return $this->pointcut;
71
    }
72
73
    /**
74
     * Specify the pointcut targeting the advice.
75
     *
76
     * @param Pointcut $pointcut The Pointcut targeting the Advice
77
     */
78
    public function setPointcut(Pointcut $pointcut)
79
    {
80
        $this->pointcut = $pointcut;
81
    }
82
83
    /**
84
     * Return string representation of object
85
     *
86
     * @return string
87
     */
88
    public function __toString()
89
    {
90
        $pointcutClass = get_class($this->getPointcut());
91
        $adviceClass   = get_class($this->getAdvice());
92
93
        return get_called_class() . ": pointcut [{$pointcutClass}]; advice [{$adviceClass}]";
94
    }
95
}
96