Conditions | 3 |
Paths | 1 |
Total Lines | 160 |
Code Lines | 106 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
86 | public function ListButtons() |
||
87 | { |
||
88 | global $context, $txt, $scripturl; |
||
89 | |||
90 | $button_names = $this->um->getButtonNames(); |
||
91 | $listOptions = array( |
||
92 | 'id' => 'menu_list', |
||
93 | 'items_per_page' => 20, |
||
94 | 'base_href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
95 | 'default_sort_col' => 'name', |
||
96 | 'default_sort_dir' => 'desc', |
||
97 | 'get_items' => array( |
||
98 | 'function' => array($this->um, 'list_getMenu'), |
||
99 | ), |
||
100 | 'get_count' => array( |
||
101 | 'function' => array($this->um, 'list_getNumButtons'), |
||
102 | ), |
||
103 | 'no_items_label' => $txt['um_menu_no_buttons'], |
||
104 | 'columns' => array( |
||
105 | 'name' => array( |
||
106 | 'header' => array( |
||
107 | 'value' => $txt['um_menu_button_name'], |
||
108 | ), |
||
109 | 'data' => array( |
||
110 | 'db_htmlsafe' => 'name', |
||
111 | ), |
||
112 | 'sort' => array( |
||
113 | 'default' => 'name', |
||
114 | 'reverse' => 'name DESC', |
||
115 | ), |
||
116 | ), |
||
117 | 'type' => array( |
||
118 | 'header' => array( |
||
119 | 'value' => $txt['um_menu_button_type'], |
||
120 | ), |
||
121 | 'data' => array( |
||
122 | 'function' => function($rowData) use ($txt) |
||
123 | { |
||
124 | return $txt['um_menu_' . $rowData['type'] . '_link']; |
||
125 | }, |
||
126 | ), |
||
127 | 'sort' => array( |
||
128 | 'default' => 'type', |
||
129 | 'reverse' => 'type DESC', |
||
130 | ), |
||
131 | ), |
||
132 | 'position' => array( |
||
133 | 'header' => array( |
||
134 | 'value' => $txt['um_menu_button_position'], |
||
135 | ), |
||
136 | 'data' => array( |
||
137 | 'function' => function($rowData) use ($txt, $button_names) |
||
138 | { |
||
139 | return sprintf( |
||
140 | '%s %s', |
||
141 | $txt['um_menu_' . $rowData['position']], |
||
142 | isset($button_names[$rowData['parent']]) |
||
143 | ? $button_names[$rowData['parent']] |
||
144 | : ucwords($rowData['parent']) |
||
145 | ); |
||
146 | }, |
||
147 | ), |
||
148 | 'sort' => array( |
||
149 | 'default' => 'position', |
||
150 | 'reverse' => 'position DESC', |
||
151 | ), |
||
152 | ), |
||
153 | 'link' => array( |
||
154 | 'header' => array( |
||
155 | 'value' => $txt['um_menu_button_link'], |
||
156 | ), |
||
157 | 'data' => array( |
||
158 | 'db_htmlsafe' => 'link', |
||
159 | ), |
||
160 | 'sort' => array( |
||
161 | 'default' => 'link', |
||
162 | 'reverse' => 'link DESC', |
||
163 | ), |
||
164 | ), |
||
165 | 'status' => array( |
||
166 | 'header' => array( |
||
167 | 'value' => $txt['um_menu_button_active'], |
||
168 | 'class' => 'centertext', |
||
169 | ), |
||
170 | 'data' => array( |
||
171 | 'function' => function($rowData) |
||
172 | { |
||
173 | return sprintf( |
||
174 | '<input type="checkbox" name="status[%1$s]" id="status_%1$s" value="%1$s"%2$s />', |
||
175 | $rowData['id_button'], |
||
176 | $rowData['status'] == 'inactive' ? '' : ' checked="checked"' |
||
177 | ); |
||
178 | }, |
||
179 | 'class' => 'centertext', |
||
180 | ), |
||
181 | 'sort' => array( |
||
182 | 'default' => 'status', |
||
183 | 'reverse' => 'status DESC', |
||
184 | ), |
||
185 | ), |
||
186 | 'actions' => array( |
||
187 | 'header' => array( |
||
188 | 'value' => $txt['um_menu_actions'], |
||
189 | 'class' => 'centertext', |
||
190 | ), |
||
191 | 'data' => array( |
||
192 | 'function' => function($rowData) use ($scripturl, $txt) |
||
193 | { |
||
194 | return sprintf( |
||
195 | '<a href="%s?action=admin;area=umen;sa=addbutton;edit;in=%d">%s</a>', |
||
196 | $scripturl, |
||
197 | $rowData['id_button'], |
||
198 | $txt['modify'] |
||
199 | ); |
||
200 | }, |
||
201 | 'class' => 'centertext', |
||
202 | ), |
||
203 | ), |
||
204 | 'check' => array( |
||
205 | 'header' => array( |
||
206 | 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
||
207 | 'class' => 'centertext', |
||
208 | ), |
||
209 | 'data' => array( |
||
210 | 'sprintf' => array( |
||
211 | 'format' => '<input type="checkbox" name="remove[]" value="%d" class="input_check" />', |
||
212 | 'params' => array( |
||
213 | 'id_button' => false, |
||
214 | ), |
||
215 | ), |
||
216 | 'class' => 'centertext', |
||
217 | ), |
||
218 | ), |
||
219 | ), |
||
220 | 'form' => array( |
||
221 | 'href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
222 | ), |
||
223 | 'additional_rows' => array( |
||
224 | array( |
||
225 | 'position' => 'below_table_data', |
||
226 | 'value' => sprintf(' |
||
227 | <input type="submit" name="removeButtons" value="%s" onclick="return confirm(\'%s\');" class="button_submit" /> |
||
228 | <input type="submit" name="removeAll" value="%s" onclick="return confirm(\'%s\');" class="button_submit" /> |
||
229 | <input type="submit" name="new" value="%s" class="button_submit" /> |
||
230 | <input type="submit" name="save" value="%s" class="button_submit" />', |
||
231 | $txt['um_menu_remove_selected'], |
||
232 | $txt['um_menu_remove_confirm'], |
||
233 | $txt['um_menu_remove_all'], |
||
234 | $txt['um_menu_remove_all_confirm'], |
||
235 | $txt['um_admin_add_button'], |
||
236 | $txt['save'] |
||
237 | ), |
||
238 | 'class' => 'righttext', |
||
239 | ), |
||
240 | ), |
||
241 | ); |
||
242 | require_once $sourcedir . '/Subs-List.php'; |
||
243 | createList($listOptions); |
||
244 | $context['sub_template'] = 'show_list'; |
||
245 | $context['default_list'] = 'menu_list'; |
||
246 | } |
||
412 |