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 |
||
10 | class CollectionDataTable extends DataTableAbstract |
||
11 | { |
||
12 | /** |
||
13 | * Collection object |
||
14 | * |
||
15 | * @var \Illuminate\Support\Collection |
||
16 | */ |
||
17 | public $collection; |
||
18 | |||
19 | /** |
||
20 | * Collection object |
||
21 | * |
||
22 | * @var \Illuminate\Support\Collection |
||
23 | */ |
||
24 | public $original; |
||
25 | |||
26 | /** |
||
27 | * CollectionEngine constructor. |
||
28 | * |
||
29 | * @param \Illuminate\Support\Collection $collection |
||
30 | */ |
||
31 | public function __construct(Collection $collection) |
||
39 | |||
40 | /** |
||
41 | * Serialize collection |
||
42 | * |
||
43 | * @param mixed $collection |
||
44 | * @return mixed|null |
||
45 | */ |
||
46 | protected function serialize($collection) |
||
50 | |||
51 | /** |
||
52 | * Append debug parameters on output. |
||
53 | * |
||
54 | * @param array $output |
||
55 | * @return array |
||
56 | */ |
||
57 | public function showDebugger(array $output) |
||
63 | |||
64 | /** |
||
65 | * Count results. |
||
66 | * |
||
67 | * @return integer |
||
68 | */ |
||
69 | public function count() |
||
73 | |||
74 | /** |
||
75 | * Perform column search. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | public function columnSearch() |
||
114 | |||
115 | /** |
||
116 | * Perform pagination. |
||
117 | * |
||
118 | * @return void |
||
119 | */ |
||
120 | public function paging() |
||
127 | |||
128 | /** |
||
129 | * Organizes works. |
||
130 | * |
||
131 | * @param bool $mDataSupport |
||
132 | * @return \Illuminate\Http\JsonResponse |
||
133 | */ |
||
134 | public function make($mDataSupport = true) |
||
157 | |||
158 | /** |
||
159 | * Revert transformed DT_Row_Index back to it's original values. |
||
160 | * |
||
161 | * @param bool $mDataSupport |
||
162 | */ |
||
163 | private function revertIndexColumn($mDataSupport) |
||
175 | |||
176 | /** |
||
177 | * Count total items. |
||
178 | * |
||
179 | * @return integer |
||
180 | */ |
||
181 | public function totalCount() |
||
185 | |||
186 | /** |
||
187 | * Get results. |
||
188 | * |
||
189 | * @return mixed |
||
190 | */ |
||
191 | public function results() |
||
195 | |||
196 | /** |
||
197 | * Perform global search for the given keyword. |
||
198 | * |
||
199 | * @param string $keyword |
||
200 | */ |
||
201 | protected function globalSearch($keyword) |
||
226 | |||
227 | /** |
||
228 | * Perform default query orderBy clause. |
||
229 | */ |
||
230 | protected function defaultOrdering() |
||
260 | |||
261 | /** |
||
262 | * Resolve callback parameter instance. |
||
263 | * |
||
264 | * @return $this |
||
265 | */ |
||
266 | protected function resolveCallbackParameter() |
||
270 | } |
||
271 |
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.