| Conditions | 10 |
| Paths | 5 |
| Total Lines | 175 |
| Code Lines | 114 |
| 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 |
||
| 47 | function ManageUltimateMenu() |
||
|
|
|||
| 48 | { |
||
| 49 | global $context, $txt, $scripturl; |
||
| 50 | |||
| 51 | // Get rid of all of em! |
||
| 52 | if (!empty($_POST['removeAll'])) |
||
| 53 | { |
||
| 54 | checkSession(); |
||
| 55 | $this->um->deleteallButtons(); |
||
| 56 | $this->um->rebuildMenu(); |
||
| 57 | redirectexit('action=admin;area=umen'); |
||
| 58 | } |
||
| 59 | // User pressed the 'remove selection button'. |
||
| 60 | elseif (!empty($_POST['removeButtons']) && !empty($_POST['remove']) && is_array($_POST['remove'])) |
||
| 61 | { |
||
| 62 | checkSession(); |
||
| 63 | |||
| 64 | // Make sure every entry is a proper integer. |
||
| 65 | foreach ($_POST['remove'] as $index => $page_id) |
||
| 66 | $_POST['remove'][(int) $index] = (int) $page_id; |
||
| 67 | |||
| 68 | // Delete the page(s)! |
||
| 69 | $this->um->deleteButton($_POST['remove']); |
||
| 70 | $this->um->rebuildMenu(); |
||
| 71 | redirectexit('action=admin;area=umen'); |
||
| 72 | } |
||
| 73 | // Changing the status? |
||
| 74 | elseif (isset($_POST['save'])) |
||
| 75 | { |
||
| 76 | checkSession(); |
||
| 77 | $this->um->updateButton($_POST); |
||
| 78 | $this->um->rebuildMenu(); |
||
| 79 | redirectexit('action=admin;area=umen'); |
||
| 80 | } |
||
| 81 | // New item? |
||
| 82 | elseif (isset($_POST['new'])) |
||
| 83 | redirectexit('action=admin;area=umen;sa=addbutton'); |
||
| 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 | 'class' => 'centertext', |
||
| 107 | ), |
||
| 108 | 'sort' => array( |
||
| 109 | 'default' => 'name', |
||
| 110 | 'reverse' => 'name DESC', |
||
| 111 | ), |
||
| 112 | ), |
||
| 113 | 'type' => array( |
||
| 114 | 'header' => array( |
||
| 115 | 'value' => $txt['um_menu_button_type'], |
||
| 116 | ), |
||
| 117 | 'data' => array( |
||
| 118 | 'function' => function($rowData) use ($txt) |
||
| 119 | { |
||
| 120 | return $txt[$rowData['type'] . '_link']; |
||
| 121 | }, |
||
| 122 | 'class' => 'centertext', |
||
| 123 | ), |
||
| 124 | 'sort' => array( |
||
| 125 | 'default' => 'type', |
||
| 126 | 'reverse' => 'type DESC', |
||
| 127 | ), |
||
| 128 | ), |
||
| 129 | 'poition' => array( |
||
| 130 | 'header' => array( |
||
| 131 | 'value' => $txt['um_menu_button_position'], |
||
| 132 | ), |
||
| 133 | 'data' => array( |
||
| 134 | 'function' => function($rowData) use ($txt, $button_names) |
||
| 135 | { |
||
| 136 | return $txt['mboards_order_' . $rowData['position']] . ' ' . (isset($button_names[$rowData['parent']]) ? $button_names[$rowData['parent']] : ucwords($rowData['parent'])); |
||
| 137 | }, |
||
| 138 | 'class' => 'centertext', |
||
| 139 | ), |
||
| 140 | 'sort' => array( |
||
| 141 | 'default' => 'position', |
||
| 142 | 'reverse' => 'position DESC', |
||
| 143 | ), |
||
| 144 | ), |
||
| 145 | 'link' => array( |
||
| 146 | 'header' => array( |
||
| 147 | 'value' => $txt['um_menu_button_link'], |
||
| 148 | ), |
||
| 149 | 'data' => array( |
||
| 150 | 'db_htmlsafe' => 'link', |
||
| 151 | 'class' => 'centertext', |
||
| 152 | ), |
||
| 153 | 'sort' => array( |
||
| 154 | 'default' => 'link', |
||
| 155 | 'reverse' => 'link DESC', |
||
| 156 | ), |
||
| 157 | ), |
||
| 158 | 'status' => array( |
||
| 159 | 'header' => array( |
||
| 160 | 'value' => $txt['um_menu_button_active'], |
||
| 161 | ), |
||
| 162 | 'data' => array( |
||
| 163 | 'function' => function($rowData) use ($txt) |
||
| 164 | { |
||
| 165 | return sprintf('<input type="checkbox" name="status[%1$s]" id="status_%1$s" value="%1$s"%2$s />', $rowData['id_button'], $rowData['status'] == 'inactive' ? '' : ' checked="checked"'); |
||
| 166 | }, |
||
| 167 | 'class' => 'centertext', |
||
| 168 | ), |
||
| 169 | 'sort' => array( |
||
| 170 | 'default' => 'status', |
||
| 171 | 'reverse' => 'status DESC', |
||
| 172 | ), |
||
| 173 | ), |
||
| 174 | 'actions' => array( |
||
| 175 | 'header' => array( |
||
| 176 | 'value' => $txt['um_menu_actions'], |
||
| 177 | ), |
||
| 178 | 'data' => array( |
||
| 179 | 'sprintf' => array( |
||
| 180 | 'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=admin;area=umen;sa=addbutton;edit;in=%1$d">' . $txt['modify'] . '</a>', |
||
| 181 | 'params' => array( |
||
| 182 | 'id_button' => false, |
||
| 183 | ), |
||
| 184 | ), |
||
| 185 | 'class' => 'centertext', |
||
| 186 | ), |
||
| 187 | ), |
||
| 188 | 'check' => array( |
||
| 189 | 'header' => array( |
||
| 190 | 'value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', |
||
| 191 | ), |
||
| 192 | 'data' => array( |
||
| 193 | 'sprintf' => array( |
||
| 194 | 'format' => '<input type="checkbox" name="remove[]" value="%1$d" class="input_check" />', |
||
| 195 | 'params' => array( |
||
| 196 | 'id_button' => false, |
||
| 197 | ), |
||
| 198 | ), |
||
| 199 | 'class' => 'centertext', |
||
| 200 | ), |
||
| 201 | ), |
||
| 202 | ), |
||
| 203 | 'form' => array( |
||
| 204 | 'href' => $scripturl . '?action=admin;area=umen;sa=manmenu', |
||
| 205 | ), |
||
| 206 | 'additional_rows' => array( |
||
| 207 | array( |
||
| 208 | 'position' => 'below_table_data', |
||
| 209 | 'value' => ' |
||
| 210 | <input type="submit" name="removeButtons" value="' . $txt['um_menu_remove_selected'] . '" onclick="return confirm(\'' . $txt['um_menu_remove_confirm'] . '\');" class="button_submit" /> |
||
| 211 | <input type="submit" name="removeAll" value="' . $txt['um_menu_remove_all'] . '" onclick="return confirm(\'' . $txt['um_menu_remove_all_confirm'] . '\');" class="button_submit" /> |
||
| 212 | <input type="submit" name="new" value="' . $txt['um_admin_add_button'] . '" class="button_submit" /> |
||
| 213 | <input type="submit" name="save" value="' . $txt['save'] . '" class="button_submit" />', |
||
| 214 | 'class' => 'righttext', |
||
| 215 | ), |
||
| 216 | ), |
||
| 217 | ); |
||
| 218 | require_once $sourcedir . '/Subs-List.php'; |
||
| 219 | createList($listOptions); |
||
| 220 | $context['sub_template'] = 'show_list'; |
||
| 221 | $context['default_list'] = 'menu_list'; |
||
| 222 | } |
||
| 344 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.