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