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 Radio extends Field |
||
9 | { |
||
10 | protected $inline = true; |
||
11 | |||
12 | protected static $css = [ |
||
13 | '/vendor/laravel-admin/AdminLTE/plugins/iCheck/all.css', |
||
14 | ]; |
||
15 | |||
16 | protected static $js = [ |
||
17 | 'vendor/laravel-admin/AdminLTE/plugins/iCheck/icheck.min.js', |
||
18 | ]; |
||
19 | |||
20 | /** |
||
21 | * Set options. |
||
22 | * |
||
23 | * @param array|callable|string $options |
||
24 | * |
||
25 | * @return $this |
||
26 | */ |
||
27 | View Code Duplication | public function options($options = []) |
|
37 | |||
38 | /** |
||
39 | * Set checked. |
||
40 | * |
||
41 | * @param array|callable|string $checked |
||
42 | * |
||
43 | * @return $this |
||
44 | */ |
||
45 | public function checked($checked = []) |
||
56 | |||
57 | |||
58 | /** |
||
59 | * Draw inline radios. |
||
60 | * |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function inline() |
||
69 | |||
70 | /** |
||
71 | * Draw stacked radios. |
||
72 | * |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function stacked() |
||
81 | |||
82 | /** |
||
83 | * Set options. |
||
84 | * |
||
85 | * @param array|callable|string $values |
||
86 | * |
||
87 | * @return $this |
||
88 | */ |
||
89 | public function values($values) |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | View Code Duplication | public function render() |
|
105 | } |
||
106 |
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.