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 |
||
31 | trait WhereTrait |
||
32 | { |
||
33 | use AbstractTrait; |
||
34 | |||
35 | /** |
||
36 | * {@inheritDoc} |
||
37 | */ |
||
38 | public function where( |
||
45 | |||
46 | /** |
||
47 | * {@inheritDoc} |
||
48 | */ |
||
49 | public function whereTpl(/*# string */ $template, $col, array $params = []) |
||
60 | |||
61 | /** |
||
62 | * {@inheritDoc} |
||
63 | */ |
||
64 | public function orWhereTpl(/*# string */ $template, $col, array $params = []) |
||
75 | |||
76 | /** |
||
77 | * {@inheritDoc} |
||
78 | */ |
||
79 | View Code Duplication | public function whereRaw(/*# string */ $rawString, array $params = []) |
|
91 | |||
92 | /** |
||
93 | * {@inheritDoc} |
||
94 | */ |
||
95 | View Code Duplication | public function orWhereRaw(/*# string */ $rawString, array $params = []) |
|
107 | |||
108 | /** |
||
109 | * {@inheritDoc} |
||
110 | */ |
||
111 | public function andWhere( |
||
118 | |||
119 | /** |
||
120 | * {@inheritDoc} |
||
121 | */ |
||
122 | public function orWhere( |
||
129 | |||
130 | /** |
||
131 | * {@inheritDoc} |
||
132 | */ |
||
133 | public function whereNot( |
||
140 | |||
141 | /** |
||
142 | * {@inheritDoc} |
||
143 | */ |
||
144 | public function orWhereNot( |
||
151 | |||
152 | /** |
||
153 | * Real where |
||
154 | * |
||
155 | * @param string|string[]|Template $col col or cols |
||
156 | * @param mixed $operator |
||
157 | * @param mixed $value |
||
158 | * @param string $logicAnd 'AND' |
||
159 | * @param string $whereNot 'WHERE NOT' |
||
160 | * @param bool $rawMode |
||
161 | * @param string $clause 'where' or 'having' |
||
162 | * @return $this |
||
163 | * @access protected |
||
164 | */ |
||
165 | protected function realWhere( |
||
186 | |||
187 | /** |
||
188 | * @param array $cols |
||
189 | * @param string $logicAnd |
||
190 | * @param string $whereNot |
||
191 | * @param bool $rawMode |
||
192 | * @access protected |
||
193 | */ |
||
194 | protected function multipleWhere( |
||
210 | |||
211 | /** |
||
212 | * Fix where('id', 18) to where('id', '=', 18) |
||
213 | * |
||
214 | * @param mixed &$operator |
||
215 | * @param mixed &$value |
||
216 | * @param bool $rawMode |
||
217 | * @access protected |
||
218 | */ |
||
219 | protected function fixOperator(&$operator, &$value, $rawMode) |
||
226 | |||
227 | /** |
||
228 | * Build WHERE |
||
229 | * |
||
230 | * @param prefix |
||
231 | * @param array $settings |
||
232 | * @return array |
||
233 | * @access protected |
||
234 | */ |
||
235 | protected function buildWhere( |
||
254 | |||
255 | /** |
||
256 | * build 'AND NOT' part of the clause part |
||
257 | * |
||
258 | * @param array &$cls |
||
259 | * @param array $where |
||
260 | * @param int $idx |
||
261 | * @access protected |
||
262 | */ |
||
263 | protected function buildAndOr(array &$cls, array $where, $idx) |
||
274 | |||
275 | /** |
||
276 | * Build 'col = val' part |
||
277 | * |
||
278 | * @param array $cls |
||
279 | * @param array $where |
||
280 | * @param array $settings |
||
281 | * @return string |
||
282 | * @access protected |
||
283 | */ |
||
284 | protected function buildCondition(array $cls, array $where, array $settings) |
||
305 | } |
||
306 |