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 |
||
17 | abstract class AbstractTwoOperandsOperator implements NodeInterface |
||
18 | { |
||
19 | use ConditionTrait; |
||
20 | |||
21 | private $leftOperand; |
||
22 | |||
23 | public function getLeftOperand() |
||
27 | |||
28 | /** |
||
29 | * Sets the leftOperand. |
||
30 | * |
||
31 | * @Important |
||
32 | * |
||
33 | * @param NodeInterface|NodeInterface[]|string $leftOperand |
||
34 | */ |
||
35 | public function setLeftOperand($leftOperand) |
||
39 | |||
40 | private $rightOperand; |
||
41 | |||
42 | public function getRightOperand() |
||
46 | |||
47 | /** |
||
48 | * Sets the rightOperand. |
||
49 | * |
||
50 | * @Important |
||
51 | * |
||
52 | * @param string|NodeInterface|NodeInterface[] $rightOperand |
||
53 | */ |
||
54 | public function setRightOperand($rightOperand) |
||
58 | |||
59 | /** |
||
60 | * Returns a Mouf instance descriptor describing this object. |
||
61 | * |
||
62 | * @param MoufManager $moufManager |
||
63 | * |
||
64 | * @return MoufInstanceDescriptor |
||
65 | */ |
||
66 | public function toInstanceDescriptor(MoufManager $moufManager) |
||
88 | |||
89 | /** |
||
90 | * Renders the object as a SQL string. |
||
91 | * |
||
92 | * @param Connection $dbConnection |
||
93 | * @param array $parameters |
||
94 | * @param number $indent |
||
95 | * @param int $conditionsMode |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY, bool $extrapolateParameters = true) |
||
123 | |||
124 | protected function getSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY, bool $extrapolateParameters = true) |
||
132 | |||
133 | /** |
||
134 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
135 | * |
||
136 | * @param VisitorInterface $visitor |
||
137 | */ |
||
138 | public function walk(VisitorInterface $visitor) |
||
163 | |||
164 | /** |
||
165 | * Returns the symbol for this operator. |
||
166 | */ |
||
167 | abstract protected function getOperatorSymbol(); |
||
168 | } |
||
169 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.