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 |
||
29 | View Code Duplication | trait GroupTrait |
|
|
|||
30 | { |
||
31 | use AbstractTrait; |
||
32 | |||
33 | /** |
||
34 | * {@inheritDoc} |
||
35 | */ |
||
36 | public function group($col) |
||
44 | |||
45 | /** |
||
46 | * {@inheritDoc} |
||
47 | */ |
||
48 | public function groupDesc($col) |
||
56 | |||
57 | /** |
||
58 | * {@inheritDoc} |
||
59 | */ |
||
60 | public function groupTpl(/*# string */ $template, $col, array $params = []) |
||
65 | |||
66 | /** |
||
67 | * {@inheritDoc} |
||
68 | */ |
||
69 | public function groupRaw(/*# string */ $rawString, array $params = []) |
||
74 | |||
75 | /** |
||
76 | * real group by |
||
77 | * @param string|string[]|Template $col column[s] |
||
78 | * @param string $suffix ''|ASC|DESC |
||
79 | * @param bool $rawMode |
||
80 | * @return $this |
||
81 | * @access protected |
||
82 | */ |
||
83 | protected function realGroup( |
||
101 | |||
102 | /** |
||
103 | * Multitple groupbys |
||
104 | * |
||
105 | * @param array $cols |
||
106 | * @param string $suffix |
||
107 | * @access protected |
||
108 | */ |
||
109 | protected function multipleGroup(array $cols, /*# string */ $suffix) |
||
115 | |||
116 | /** |
||
117 | * Build GROUP BY |
||
118 | * |
||
119 | * @param string $prefix |
||
120 | * @param array $settings |
||
121 | * @return string |
||
122 | * @access protected |
||
123 | */ |
||
124 | protected function buildGroup( |
||
130 | } |
||
131 |
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.