PointcutPointcut::__clone()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * \AppserverIo\Doppelgaenger\Entities\Pointcut\PointcutPointcut
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Bernhard Wick <[email protected]>
15
 * @copyright 2015 TechDivision GmbH - <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/doppelgaenger
18
 * @link      http://www.appserver.io/
19
 */
20
21
namespace AppserverIo\Doppelgaenger\Entities\Pointcuts;
22
23
use AppserverIo\Doppelgaenger\Entities\Definitions\FunctionDefinition;
24
25
/**
26
 * Pointcut expression for specifying a collection of other pointcuts and annotations expressing them
27
 *
28
 * @author    Bernhard Wick <[email protected]>
29
 * @copyright 2015 TechDivision GmbH - <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/appserver-io/doppelgaenger
32
 * @link      http://www.appserver.io/
33
 *
34
 * @Target({"ADVICE"})
35
 */
36
class PointcutPointcut extends AbstractPointcut
37
{
38
39
    /**
40
     * Connector for referencing of several pointcuts at once
41
     *
42
     * @var string EXPRESSION_CONNECTOR
43
     */
44
    const EXPRESSION_CONNECTOR = ',';
45
46
    /**
47
     * Whether or not the pointcut is considered static, meaning is has to be weaved and evaluated during runtime
48
     * anyway
49
     *
50
     * @var boolean IS_STATIC
51
     */
52
    const IS_STATIC = false;
53
54
    /**
55
     * The type of this pointcut
56
     *
57
     * @var string TYPE
58
     */
59
    const TYPE = 'pointcut';
60
61
    /**
62
     * Pointcuts referenced by this pointcut's expression
63
     *
64
     * @var \AppserverIo\Doppelgaenger\Interfaces\PointcutInterface[] $referencedPointcuts
65
     */
66
    protected $referencedPointcuts;
67
68
    /**
69
     * Magic __clone method to allow for deep clones of pointcut instances
70
     *
71
     * @return void
72
     */
73
    public function __clone()
74
    {
75
        foreach ($this->referencedPointcuts as $key => $referencedPointcut) {
76
            $this->referencedPointcuts[$key] = clone $referencedPointcut;
77
        }
78
    }
79
80
    /**
81
     * Returns a string representing a boolean condition which can be used to determine if
82
     * the pointcut has to be executed
83
     *
84
     * @return string
85
     */
86
    public function getConditionString()
87
    {
88
        return 'true';
89
    }
90
91
    /**
92
     * Returns a string representing the actual execution of the pointcut logic
93
     *
94
     * @param string|null $assignTo Should the result be assigned and stored for later use? If so, to what?
95
     *
96
     * @return string
97
     */
98
    public function getExecutionString($assignTo = null)
99
    {
100
        return '';
101
    }
102
103
    /**
104
     * Getter for the $referencedPointcuts property
105
     *
106
     * @return array
107
     */
108
    public function getReferencedPointcuts()
109
    {
110
        return $this->referencedPointcuts;
111
    }
112
113
    /**
114
     * Whether or not the pointcut matches a given candidate.
115
     * Weave pointcuts will always return true, as they do not pose any condition
116
     *
117
     * @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern())
118
     *
119
     * @return boolean
120
     */
121
    public function matches($candidate)
122
    {
123
        // if we do not get a function definition we can already assume there is no match
124
        if (!$candidate instanceof FunctionDefinition) {
125
            return false;
126
        }
127
128
        // iterate all referenced pointcuts and return true if one of them matches
129
        foreach ($this->referencedPointcuts as $referencedPointcut) {
130
            if ($referencedPointcut->pointcutExpression->getPointcut()->matches($candidate)) {
0 ignored issues
show
Bug introduced by
Accessing pointcutExpression on the interface AppserverIo\Doppelgaenge...faces\PointcutInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
131
                return true;
132
            }
133
        }
134
135
        return false;
136
    }
137
138
    /**
139
     * Setter for the $referencedPointcuts property
140
     *
141
     * @param \AppserverIo\Doppelgaenger\Interfaces\PointcutInterface[] $referencedPointcuts Pointcuts referenced by this pointcut's expression
142
     *
143
     * @return null
144
     */
145
    public function setReferencedPointcuts(array $referencedPointcuts)
146
    {
147
        $this->referencedPointcuts = $referencedPointcuts;
148
    }
149
}
150