Completed
Pull Request — master (#320)
by Alexander
03:17
created

DefaultPointcutAdvisor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
58
            );
59
        }
60
61 2
        return $advice;
62
    }
63
64
    /**
65
     * Get the Pointcut that drives this advisor.
66
     */
67 2
    public function getPointcut() : Pointcut
68
    {
69 2
        return $this->pointcut;
70
    }
71
}
72