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 |
||
9 | class SearchPane extends Fluent |
||
10 | { |
||
11 | /** |
||
12 | * @param array $options |
||
13 | * @return static |
||
14 | */ |
||
15 | public static function make(array $options = []) |
||
19 | |||
20 | /** |
||
21 | * @param bool $value |
||
22 | * @return static |
||
23 | * @see https://datatables.net/reference/option/searchPanes.cascadePanes |
||
24 | */ |
||
25 | public function cascadePanes($value = true) |
||
31 | |||
32 | /** |
||
33 | * @param bool $value |
||
34 | * @return static |
||
35 | * @see https://datatables.net/reference/option/searchPanes.clear |
||
36 | */ |
||
37 | public function clear($value = true) |
||
43 | |||
44 | /** |
||
45 | * @param array $value |
||
46 | * @return static |
||
47 | * @see https://datatables.net/reference/option/searchPanes.columns |
||
48 | */ |
||
49 | public function columns(array $value = []) |
||
55 | |||
56 | /** |
||
57 | * @param bool $value |
||
58 | * @return static |
||
59 | * @see https://datatables.net/reference/option/searchPanes.controls |
||
60 | */ |
||
61 | public function controls($value = true) |
||
67 | |||
68 | /** |
||
69 | * @param array $value |
||
70 | * @return static |
||
71 | * @see https://datatables.net/reference/option/searchPanes.dtOpts |
||
72 | * @see https://datatables.net/reference/option/columns.searchPanes.dtOpts |
||
73 | */ |
||
74 | public function dtOpts(array $value = []) |
||
80 | |||
81 | /** |
||
82 | * @param mixed $value |
||
83 | * @return static |
||
84 | * @see https://datatables.net/reference/option/searchPanes.emptyMessage |
||
85 | */ |
||
86 | public function emptyMessage($value) |
||
92 | |||
93 | /** |
||
94 | * @param mixed $value |
||
95 | * @return static |
||
96 | * @see https://datatables.net/reference/option/searchPanes.filterChanged |
||
97 | */ |
||
98 | public function filterChanged($value) |
||
104 | |||
105 | /** |
||
106 | * @param bool $value |
||
107 | * @return static |
||
108 | * @see https://datatables.net/reference/option/searchPanes.hideCount |
||
109 | */ |
||
110 | public function hideCount($value = true) |
||
116 | |||
117 | /** |
||
118 | * @param mixed $value |
||
119 | * @return static |
||
120 | * @see https://datatables.net/reference/option/searchPanes.layout |
||
121 | */ |
||
122 | public function layout($value) |
||
128 | |||
129 | /** |
||
130 | * @param mixed $value |
||
131 | * @return static |
||
132 | * @see https://datatables.net/reference/option/searchPanes.order |
||
133 | */ |
||
134 | public function order($value) |
||
140 | |||
141 | /** |
||
142 | * @param boolean $value |
||
143 | * @return static |
||
144 | * @see https://datatables.net/reference/option/searchPanes.orderable |
||
145 | */ |
||
146 | public function orderable($value = true) |
||
152 | |||
153 | /** |
||
154 | * @param array $value |
||
155 | * @return static |
||
156 | * @see https://datatables.net/reference/option/searchPanes.panes |
||
157 | */ |
||
158 | public function panes(array $value) |
||
172 | |||
173 | /** |
||
174 | * @param mixed $value |
||
175 | * @return static |
||
176 | * @see https://datatables.net/reference/option/searchPanes.threshold |
||
177 | */ |
||
178 | public function threshold($value) |
||
184 | |||
185 | /** |
||
186 | * @param boolean $value |
||
187 | * @return static |
||
188 | * @see https://datatables.net/reference/option/searchPanes.viewTotal |
||
189 | */ |
||
190 | public function viewTotal($value = true) |
||
196 | |||
197 | /** |
||
198 | * @param boolean $value |
||
199 | * @return static |
||
200 | * @see https://datatables.net/reference/option/searchPanes.viewTotal |
||
201 | */ |
||
202 | public function hideTotal($value = true) |
||
208 | |||
209 | /** |
||
210 | * Get options from a model. |
||
211 | * |
||
212 | * @param mixed $model |
||
213 | * @param string $value |
||
214 | * @param string $key |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function modelOptions($model, $value, $key = 'id') |
||
223 | |||
224 | /** |
||
225 | * @param mixed $value |
||
226 | * @return static |
||
227 | * @see https://datatables.net/reference/option/columns.searchPanes.options |
||
228 | */ |
||
229 | View Code Duplication | public function options($value) |
|
239 | |||
240 | /** |
||
241 | * Get options from a table. |
||
242 | * |
||
243 | * @param mixed $table |
||
244 | * @param string $value |
||
245 | * @param string $key |
||
246 | * @param \Closure $whereCallback |
||
247 | * @param string|null $key |
||
248 | * @return $this |
||
249 | */ |
||
250 | public function tableOptions($table, $value, $key = 'id', \Closure $whereCallback = null, $connection = null) |
||
256 | |||
257 | /** |
||
258 | * @param mixed $value |
||
259 | * @return static |
||
260 | * @see https://datatables.net/reference/option/columns.searchPanes.className |
||
261 | */ |
||
262 | public function className($value) |
||
268 | |||
269 | /** |
||
270 | * @param mixed $value |
||
271 | * @return static |
||
272 | * @see https://datatables.net/reference/option/searchPanes.panes.header |
||
273 | */ |
||
274 | public function header($value) |
||
280 | |||
281 | /** |
||
282 | * @param bool $value |
||
283 | * @return static |
||
284 | * @see https://datatables.net/reference/option/columns.searchPanes.show |
||
285 | */ |
||
286 | public function show($value = true) |
||
292 | |||
293 | /** |
||
294 | * @param mixed $value |
||
295 | * @return static |
||
296 | * @see https://datatables.net/reference/option/columns.searchPanes.name |
||
297 | */ |
||
298 | public function name($value) |
||
304 | |||
305 | /** |
||
306 | * @param mixed $value |
||
307 | * @return static |
||
308 | * @see https://datatables.net/reference/option/columns.searchPanes.orthogonal |
||
309 | */ |
||
310 | public function orthogonal($value) |
||
316 | } |
||
317 |
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.