Completed
Pull Request — 2.x (#349)
by Alexander
02:20
created

DefaultPointcutAdvisor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 46
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPointcut() 0 4 1
A __construct() 0 5 1
A getAdvice() 0 12 3
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\Intercept\Interceptor;
17
use Go\Aop\Pointcut;
18
use Go\Aop\PointcutAdvisor;
19
use Go\Aop\PointFilter;
20
21
/**
22
 * Convenient Pointcut-driven Advisor implementation.
23
 *
24
 * This is the most commonly used Advisor implementation. It can be used with any pointcut and advice type,
25
 * except for introductions. There is normally no need to subclass this class, or to implement custom Advisors.
26
 */
27
class DefaultPointcutAdvisor extends AbstractGenericAdvisor implements PointcutAdvisor
28
{
29
30
    /**
31
     * Pointcut instance
32
     *
33
     * @var Pointcut
34
     */
35
    private $pointcut;
36
37
    /**
38
     * Create a DefaultPointcutAdvisor, specifying Pointcut and Advice.
39
     *
40
     * @param Pointcut $pointcut The Pointcut targeting the Advice
41
     * @param Advice $advice The Advice to run when Pointcut matches
42
     */
43 2
    public function __construct(Pointcut $pointcut, Advice $advice)
44
    {
45 2
        $this->pointcut = $pointcut;
46 2
        parent::__construct($advice);
47 2
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 2
    public function getAdvice(): Advice
53
    {
54 2
        $advice = parent::getAdvice();
55 2
        if (($advice instanceof Interceptor) && ($this->pointcut->getKind() & PointFilter::KIND_DYNAMIC)) {
56
            $advice = new DynamicInvocationMatcherInterceptor(
57
                $this->pointcut,
58
                $advice
59
            );
60
        }
61
62 2
        return $advice;
63
    }
64
65
    /**
66
     * Get the Pointcut that drives this advisor.
67
     */
68 2
    public function getPointcut(): Pointcut
69
    {
70 2
        return $this->pointcut;
71
    }
72
}
73