OrPointcut::matches()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * \AppserverIo\Doppelgaenger\Entities\Pointcuts\OrPointcut
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
/**
24
 * Pointcut to or-connect two other pointcuts logically
25
 *
26
 * @author    Bernhard Wick <[email protected]>
27
 * @copyright 2015 TechDivision GmbH - <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/appserver-io/doppelgaenger
30
 * @link      http://www.appserver.io/
31
 *
32
 * @Target({"ADVICE", "METHOD","PROPERTY"})
33
 */
34
class OrPointcut extends AbstractConnectorPointcut
35
{
36
    /**
37
     * Connector which connects two pointcuts in a logical manner
38
     *
39
     * @var string CONNECTOR
40
     */
41
    const CONNECTOR = self::CONNECTOR_OR;
42
43
    /**
44
     * The type of this pointcut
45
     *
46
     * @var string TYPE
47
     */
48
    const TYPE = 'or';
49
50
    /**
51
     * Returns a string representing a boolean condition which can be used to determine if
52
     * the pointcut has to be executed
53
     *
54
     * @return string
55
     */
56
    public function getConditionString()
57
    {
58
        // if one of these conditions is true we can default to 'true'
59
        if ($this->leftPointcut->getConditionString() === 'true' || $this->rightPointcut->getConditionString() === 'true') {
60
            return 'true';
61
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
62 View Code Duplication
        } else {
63
            return '(' . $this->leftPointcut->getConditionString() . $this->getConnector().
64
            $this->rightPointcut->getConditionString() . ')';
65
        }
66
    }
67
68
    /**
69
     * Whether or not the pointcut matches a given candidate.
70
     * For connector pointcuts this mostly depends on the connected pointcuts
71
     *
72
     * @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern())
73
     *
74
     * @return boolean
75
     */
76
    public function matches($candidate)
77
    {
78
        return ($this->leftPointcut->matches($candidate) || $this->rightPointcut->matches($candidate));
79
    }
80
}
81