Completed
Pull Request — master (#463)
by Alexander
30:17 queued 05:15
created

PointcutReference   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 83
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * Go! AOP framework
6
 *
7
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
8
 *
9
 * This source file is subject to the license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Go\Aop\Pointcut;
14
15
use Go\Aop\Pointcut;
16
use Go\Aop\PointFilter;
17
use Go\Core\AspectContainer;
18
use Go\Core\AspectKernel;
19
20
/**
21
 * Reference to the pointcut holds an id of pointcut to fetch when needed
22
 */
23
final class PointcutReference implements Pointcut
24
{
25
    private ?Pointcut $pointcut = null;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_FUNCTION or T_CONST
Loading history...
26
27
    /**
28
     * Name of the pointcut to fetch from the container
29
     */
30
    private string $pointcutId;
31
32
    /**
33
     * Instance of aspect container
34
     */
35
    private AspectContainer $container;
36
37
    /**
38
     * Pointcut reference constructor
39
     */
40
    public function __construct(AspectContainer $container, string $pointcutId)
41
    {
42
        $this->container  = $container;
43
        $this->pointcutId = $pointcutId;
44
    }
45
46
    /**
47
     * Performs matching of point of code
48
     *
49
     * @param mixed              $point     Specific part of code, can be any Reflection class
50
     * @param null|mixed         $context   Related context, can be class or namespace
51
     * @param null|string|object $instance  Invocation instance or string for static calls
52
     * @param null|array         $arguments Dynamic arguments for method
53
     */
54
    public function matches($point, $context = null, $instance = null, array $arguments = null): bool
55
    {
56
        return $this->getPointcut()->matches($point, $context, $instance, $arguments);
57
    }
58
59
    /**
60
     * Returns the kind of point filter
61
     */
62
    public function getKind(): int
63
    {
64
        return $this->getPointcut()->getKind();
65
    }
66
67
    /**
68
     * Return the class filter for this pointcut.
69
     */
70
    public function getClassFilter(): PointFilter
71
    {
72
        return $this->getPointcut()->getClassFilter();
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78
    public function __sleep()
79
    {
80
        return ['pointcutId'];
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86
    public function __wakeup()
87
    {
88
        $this->container = AspectKernel::getInstance()->getContainer();
89
    }
90
91
    /**
92
     * Returns a real pointcut from the container
93
     */
94
    private function getPointcut(): Pointcut
95
    {
96
        if (!$this->pointcut) {
97
            $this->pointcut = $this->container->getPointcut($this->pointcutId);
98
        }
99
100
        return $this->pointcut;
101
    }
102
}
103