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 |
||
32 | class BasicAssertion extends AbstractAssertion |
||
33 | { |
||
34 | /** |
||
35 | * @var string $firstOperand The first operand to compare |
||
36 | */ |
||
37 | public $firstOperand; |
||
38 | |||
39 | /** |
||
40 | * @var string $secondOperand The second operand to compare |
||
41 | */ |
||
42 | public $secondOperand; |
||
43 | |||
44 | /** |
||
45 | * @var string $operator The operator used for comparison |
||
46 | */ |
||
47 | public $operator; |
||
48 | |||
49 | /** |
||
50 | * @var array $inversionMapping A map to inverse operators |
||
51 | */ |
||
52 | protected $inversionMapping; |
||
53 | |||
54 | /** |
||
55 | * Default constructor |
||
56 | * |
||
57 | * @param string $firstOperand The first operand to compare |
||
58 | * @param string $secondOperand The second operand to compare |
||
59 | * @param string $operator The operator used for comparison |
||
60 | */ |
||
61 | public function __construct($firstOperand = '', $secondOperand = '', $operator = '') |
||
82 | |||
83 | /** |
||
84 | * Will return a string representation of this assertion |
||
85 | * |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getString() |
||
92 | |||
93 | /** |
||
94 | * Will return an inverted string representation. |
||
95 | * Implemented here, as we want to check if there is an entry in our inversion map we can use |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function getInvertString() |
||
107 | |||
108 | /** |
||
109 | * Invert the logical meaning of this assertion |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function invert() |
||
132 | } |
||
133 |