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 |
||
30 | trait OrderByTrait |
||
31 | { |
||
32 | /** |
||
33 | * {@inheritDoc} |
||
34 | */ |
||
35 | public function orderBy($col) |
||
39 | |||
40 | /** |
||
41 | * {@inheritDoc} |
||
42 | */ |
||
43 | public function orderByDesc($col) |
||
47 | |||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | */ |
||
51 | public function orderByTpl(/*# string */ $template, $col) |
||
55 | |||
56 | /** |
||
57 | * {@inheritDoc} |
||
58 | */ |
||
59 | public function orderByRaw(/*# string */ $rawString) |
||
63 | |||
64 | /** |
||
65 | * @param string|string[] $col |
||
66 | * @param string $suffix 'ASC' or 'DESC' |
||
67 | * @param bool $rawMode |
||
68 | * @return $this |
||
69 | * @access protected |
||
70 | */ |
||
71 | View Code Duplication | protected function realOrderBy( |
|
84 | |||
85 | /** |
||
86 | * Build ORDER BY |
||
87 | * |
||
88 | * @param array $settings |
||
89 | * @return string |
||
90 | * @access protected |
||
91 | */ |
||
92 | protected function buildOrderby(array $settings)/*# : string */ |
||
103 | |||
104 | abstract protected function isRaw($str, /*# bool */ $rawMode)/*# : bool */; |
||
114 | } |
||
115 |
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.