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 |
||
8 | class NavigationDataTable extends DataTable |
||
9 | { |
||
10 | /** |
||
11 | * Display ajax response. |
||
12 | * |
||
13 | * @return \Illuminate\Http\JsonResponse |
||
14 | */ |
||
15 | public function ajax() |
||
29 | |||
30 | /** |
||
31 | * Get the query object to be processed by datatables. |
||
32 | * |
||
33 | * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder |
||
34 | */ |
||
35 | public function query() |
||
41 | |||
42 | /** |
||
43 | * Optional method if you want to use html builder. |
||
44 | * |
||
45 | * @return \Yajra\Datatables\Html\Builder |
||
46 | */ |
||
47 | View Code Duplication | public function html() |
|
55 | |||
56 | /** |
||
57 | * Get columns. |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | private function getColumns() |
||
83 | |||
84 | /** |
||
85 | * @return array |
||
86 | */ |
||
87 | View Code Duplication | protected function getBuilderParameters() |
|
103 | |||
104 | /** |
||
105 | * Get filename for export. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | protected function filename() |
||
113 | } |
||
114 |
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.