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 |
||
46 | class Expression implements NodeInterface |
||
47 | { |
||
48 | private $baseExpression; |
||
49 | |||
50 | /** |
||
51 | * Returns the base expression (the string that generated this expression). |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getBaseExpression() |
||
59 | |||
60 | /** |
||
61 | * Sets the base expression (the string that generated this expression). |
||
62 | * |
||
63 | * @param string $baseExpression |
||
64 | */ |
||
65 | public function setBaseExpression($baseExpression) |
||
69 | |||
70 | private $subTree; |
||
71 | |||
72 | public function getSubTree() |
||
76 | |||
77 | /** |
||
78 | * Sets the subtree. |
||
79 | * |
||
80 | * @Important |
||
81 | * |
||
82 | * @param array<NodeInterface>|NodeInterface $subTree |
||
83 | */ |
||
84 | public function setSubTree($subTree) |
||
89 | |||
90 | private $alias; |
||
91 | |||
92 | public function getAlias() |
||
96 | |||
97 | /** |
||
98 | * Sets the alias. |
||
99 | * |
||
100 | * @Important |
||
101 | * |
||
102 | * @param string $alias |
||
103 | */ |
||
104 | public function setAlias($alias) |
||
108 | |||
109 | private $direction; |
||
110 | |||
111 | public function getDiretion() |
||
115 | |||
116 | /** |
||
117 | * Sets the direction. |
||
118 | * |
||
119 | * @Important |
||
120 | * |
||
121 | * @param string $direction |
||
122 | */ |
||
123 | public function setDirection($direction) |
||
127 | |||
128 | private $brackets = false; |
||
129 | |||
130 | /** |
||
131 | * Returns true if the expression is between brackets. |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function hasBrackets() |
||
139 | |||
140 | /** |
||
141 | * Sets to true if the expression is between brackets. |
||
142 | * |
||
143 | * @Important |
||
144 | * |
||
145 | * @param bool $brackets |
||
146 | */ |
||
147 | public function setBrackets($brackets) |
||
151 | |||
152 | /** |
||
153 | * Returns a Mouf instance descriptor describing this object. |
||
154 | * |
||
155 | * @param MoufManager $moufManager |
||
156 | * |
||
157 | * @return MoufInstanceDescriptor |
||
158 | */ |
||
159 | public function toInstanceDescriptor(MoufManager $moufManager) |
||
170 | |||
171 | /** |
||
172 | * Renders the object as a SQL string. |
||
173 | * |
||
174 | * @param Connection $dbConnection |
||
175 | * @param array $parameters |
||
176 | * @param number $indent |
||
177 | * @param int $conditionsMode |
||
178 | * |
||
179 | * @return string |
||
180 | */ |
||
181 | public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY) |
||
197 | |||
198 | /** |
||
199 | * Walks the tree of nodes, calling the visitor passed in parameter. |
||
200 | * |
||
201 | * @param VisitorInterface $visitor |
||
202 | */ |
||
203 | View Code Duplication | public function walk(VisitorInterface $visitor) |
|
232 | } |
||
233 |
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.