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 Button extends Fluent implements Arrayable |
||
9 | { |
||
10 | use HasAuthorizations; |
||
11 | |||
12 | /** |
||
13 | * Make a new button instance. |
||
14 | * |
||
15 | * @param string|array $options |
||
16 | * @return Button |
||
17 | */ |
||
18 | public static function make($options = []) |
||
26 | |||
27 | /** |
||
28 | * Make a raw button that does not extend anything. |
||
29 | * |
||
30 | * @param array $options |
||
31 | * @return \Yajra\DataTables\Html\Button |
||
32 | */ |
||
33 | public static function raw($options = []) |
||
41 | |||
42 | /** |
||
43 | * Set extend option value. |
||
44 | * |
||
45 | * @param string $value |
||
46 | * @return $this |
||
47 | */ |
||
48 | public function extend($value) |
||
54 | |||
55 | /** |
||
56 | * Set editor option value. |
||
57 | * |
||
58 | * @param string $value |
||
59 | * @return $this |
||
60 | */ |
||
61 | public function editor($value) |
||
67 | |||
68 | /** |
||
69 | * @param array $buttons |
||
70 | * @return $this |
||
71 | */ |
||
72 | View Code Duplication | public function buttons(array $buttons) |
|
84 | |||
85 | /** |
||
86 | * @param array $buttons |
||
87 | * @return $this |
||
88 | * @see https://editor.datatables.net/examples/api/cancelButton |
||
89 | */ |
||
90 | View Code Duplication | public function formButtons(array $buttons) |
|
102 | |||
103 | /** |
||
104 | * Set className option value. |
||
105 | * |
||
106 | * @param string $value |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function className($value) |
||
115 | |||
116 | /** |
||
117 | * Set text option value. |
||
118 | * |
||
119 | * @param string $value |
||
120 | * @return $this |
||
121 | */ |
||
122 | public function text($value) |
||
128 | |||
129 | /** |
||
130 | * Set name option value. |
||
131 | * |
||
132 | * @param string $value |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function name($value) |
||
141 | |||
142 | /** |
||
143 | * Set columns option value. |
||
144 | * |
||
145 | * @param mixed $value |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function columns($value) |
||
154 | |||
155 | /** |
||
156 | * Set exportOptions option value. |
||
157 | * |
||
158 | * @param mixed $value |
||
159 | * @return $this |
||
160 | */ |
||
161 | public function exportOptions($value) |
||
167 | |||
168 | /** |
||
169 | * Set action to submit the form. |
||
170 | * |
||
171 | * @return \Yajra\DataTables\Html\Button |
||
172 | */ |
||
173 | public function actionSubmit() |
||
177 | |||
178 | /** |
||
179 | * Set action option value. |
||
180 | * |
||
181 | * @param string $value |
||
182 | * @return $this |
||
183 | */ |
||
184 | public function action($value) |
||
190 | |||
191 | /** |
||
192 | * Set editor class action handler. |
||
193 | * |
||
194 | * @param string $action |
||
195 | * @return \Yajra\DataTables\Html\Button |
||
196 | */ |
||
197 | public function actionHandler($action) |
||
201 | |||
202 | /** |
||
203 | * Set action to close the form. |
||
204 | * |
||
205 | * @return \Yajra\DataTables\Html\Button |
||
206 | */ |
||
207 | public function actionClose() |
||
211 | } |
||
212 |
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.