AndPointcut   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 7.55 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 1
cbo 2
dl 4
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConditionString() 4 17 5
A matches() 0 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * \AppserverIo\Doppelgaenger\Entities\Pointcuts\AndPointcut
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 and-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 AndPointcut 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_AND;
42
43
    /**
44
     * The type of this pointcut
45
     *
46
     * @var string TYPE
47
     */
48
    const TYPE = 'and';
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
        // we have to check if any of these conditions can be omitted in terms of boolean algebra
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
        } elseif ($this->leftPointcut->getConditionString() === 'true') {
63
            return $this->rightPointcut->getConditionString();
64
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
65
        } elseif ($this->rightPointcut->getConditionString() === 'true') {
66
            return $this->leftPointcut->getConditionString();
67
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
68 View Code Duplication
        } else {
69
            return '(' . $this->leftPointcut->getConditionString() . $this->getConnector().
70
            $this->rightPointcut->getConditionString() . ')';
71
        }
72
    }
73
74
    /**
75
     * Whether or not the pointcut matches a given candidate.
76
     * For connector pointcuts this mostly depends on the connected pointcuts
77
     *
78
     * @param mixed $candidate Candidate to match against the pointcuts match pattern (getMatchPattern())
79
     *
80
     * @return boolean
81
     */
82
    public function matches($candidate)
83
    {
84
        return ($this->leftPointcut->matches($candidate) && $this->rightPointcut->matches($candidate));
85
    }
86
}
87