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