Conditions | 1 |
Paths | 1 |
Total Lines | 120 |
Code Lines | 95 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
15 | static function makeForm($statisticId, $moduleId, $row) |
||
16 | { |
||
17 | $form = []; |
||
18 | $form[] = [ |
||
19 | 'label' => 'Privilege(s)', |
||
20 | 'name' => 'cms_privileges', |
||
21 | 'type' => 'select2_datatable', |
||
22 | 'placeholder' => '** You can choose multiple privileges', |
||
23 | 'options' => [ |
||
24 | 'table' => 'cms_privileges', |
||
25 | 'field_label' => 'name', |
||
26 | 'field_value' => 'name', |
||
27 | 'sql_where' => null, |
||
28 | 'sql_orderby' => null, |
||
29 | 'limit' => null, |
||
30 | 'ajax_mode' => false, |
||
31 | 'allow_clear' => true, |
||
32 | 'multiple' => false, |
||
33 | 'multiple_result_format' => 'JSON', |
||
34 | ], |
||
35 | ]; |
||
36 | $form[] = [ |
||
37 | 'label' => 'Name', |
||
38 | 'name' => 'name', |
||
39 | 'type' => 'text', |
||
40 | 'required' => true, |
||
41 | 'validation' => 'required|min:3|max:255|alpha_spaces', |
||
42 | 'placeholder' => 'You can only enter the letter only', |
||
43 | ]; |
||
44 | $form[] = [ |
||
45 | 'label' => 'Type', |
||
46 | 'name' => 'type', |
||
47 | 'type' => 'radio', |
||
48 | 'required' => true, |
||
49 | 'dataenum' => MenuTypes::all(), |
||
50 | 'value' => MenuTypes::Module, |
||
51 | ]; |
||
52 | |||
53 | $form[] = [ |
||
54 | 'label' => 'Module', |
||
55 | 'name' => 'module_slug', |
||
56 | 'type' => 'select2_datatable', |
||
57 | 'options' => [ |
||
58 | 'table' => 'cms_moduls', |
||
59 | 'field_label' => 'name', |
||
60 | 'field_value' => 'id', |
||
61 | 'sql_where' => 'is_protected = 0', |
||
62 | ], |
||
63 | 'value' => $moduleId, |
||
64 | ]; |
||
65 | |||
66 | $form[] = [ |
||
67 | 'label' => 'Statistic', |
||
68 | 'name' => 'statistic_slug', |
||
69 | 'type' => 'select2_datatable', |
||
70 | 'options' => [ |
||
71 | 'table' => 'cms_statistics', |
||
72 | 'field_label' => 'name', |
||
73 | 'field_value' => 'id', |
||
74 | ], |
||
75 | 'style' => 'display:none', |
||
76 | 'value' => $statisticId, |
||
77 | ]; |
||
78 | |||
79 | $form[] = [ |
||
80 | 'label' => 'Value', |
||
81 | 'name' => 'path', |
||
82 | 'type' => 'text', |
||
83 | 'help' => 'If you select type controller, you can fill this field with controller name, you may include the method also', |
||
84 | 'placeholder' => 'NameController or NameController@methodName', |
||
85 | 'style' => 'display:none', |
||
86 | ]; |
||
87 | |||
88 | $fontawesome = FontAwesome::cssClass(); |
||
89 | |||
90 | $form[] = [ |
||
91 | 'label' => 'Icon', |
||
92 | 'name' => 'icon', |
||
93 | 'type' => 'custom_html', |
||
94 | 'options' => [ |
||
95 | 'html' => view('crudbooster::components.list_icon', compact('fontawesome', 'row'))->render(), |
||
96 | ], |
||
97 | 'required' => true, |
||
98 | ]; |
||
99 | $form[] = [ |
||
100 | 'label' => 'Color', |
||
101 | 'name' => 'color', |
||
102 | 'type' => 'select2_dataenum', |
||
103 | 'options' => [ |
||
104 | 'enum' => ['normal', 'red', 'green', 'aqua', 'light-blue', 'yellow', 'muted'], |
||
105 | 'value' => [], |
||
106 | 'allow_clear' => false, |
||
107 | 'multiple' => false, |
||
108 | 'multiple_result_format' => null, |
||
109 | ], |
||
110 | 'required' => true, |
||
111 | 'value' => 'normal', |
||
112 | ]; |
||
113 | |||
114 | $form[] = [ |
||
115 | 'label' => 'Active', |
||
116 | 'name' => 'is_active', |
||
117 | 'type' => 'radio', |
||
118 | 'required' => true, |
||
119 | 'validation' => 'required|integer', |
||
120 | 'dataenum' => ['1|Active', '0|InActive'], |
||
121 | 'value' => '1', |
||
122 | ]; |
||
123 | |||
124 | $form[] = [ |
||
125 | 'label' => 'Dashboard', |
||
126 | 'name' => 'is_dashboard', |
||
127 | 'type' => 'radio', |
||
128 | 'required' => true, |
||
129 | 'validation' => 'required|integer', |
||
130 | 'dataenum' => ['1|Yes', '0|No'], |
||
131 | 'value' => '0', |
||
132 | ]; |
||
133 | |||
134 | return $form; |
||
135 | } |
||
136 | } |