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 OrderTrait |
||
32 | { |
||
33 | use AbstractTrait; |
||
34 | |||
35 | /** |
||
36 | * {@inheritDoc} |
||
37 | */ |
||
38 | public function order($col) |
||
42 | |||
43 | /** |
||
44 | * {@inheritDoc} |
||
45 | */ |
||
46 | public function orderDesc($col) |
||
50 | |||
51 | /** |
||
52 | * {@inheritDoc} |
||
53 | */ |
||
54 | public function orderTpl(/*# string */ $template, $col) |
||
58 | |||
59 | /** |
||
60 | * {@inheritDoc} |
||
61 | */ |
||
62 | public function orderRaw(/*# string */ $rawString) |
||
67 | |||
68 | /** |
||
69 | * Real orderby |
||
70 | * |
||
71 | * @param string|string[]|Template $col |
||
72 | * @param string $suffix 'ASC' or 'DESC' |
||
73 | * @param bool $rawMode |
||
74 | * @return $this |
||
75 | * @access protected |
||
76 | */ |
||
77 | View Code Duplication | protected function realOrder( |
|
94 | |||
95 | /** |
||
96 | * Multitple orderbys |
||
97 | * |
||
98 | * @param array $cols |
||
99 | * @param string $suffix 'ASC' or 'DESC' |
||
100 | * @access protected |
||
101 | */ |
||
102 | protected function multipleOrder(array $cols, /*# sting */ $suffix) |
||
108 | |||
109 | /** |
||
110 | * Build ORDER BY |
||
111 | * |
||
112 | * @param string $prefix |
||
113 | * @param array $settings |
||
114 | * @return string |
||
115 | * @access protected |
||
116 | */ |
||
117 | protected function buildOrder( |
||
123 | } |
||
124 |