| Conditions | 25 |
| Paths | 25 |
| Total Lines | 230 |
| Code Lines | 131 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 acp_categories_config() |
||
| 82 | { |
||
| 83 | $this->language->add_lang('acp/language'); |
||
| 84 | $mode = $this->request->variable('mode', ''); |
||
| 85 | $action = $this->request->variable('action', ''); |
||
| 86 | $id = $this->request->variable('id', 0); |
||
| 87 | $form_key = 'sylver35/smiliescat'; |
||
| 88 | add_form_key($form_key); |
||
| 89 | |||
| 90 | if ($action) |
||
| 91 | { |
||
| 92 | switch ($action) |
||
| 93 | { |
||
| 94 | case 'config_cat': |
||
| 95 | |||
| 96 | if (!check_form_key($form_key)) |
||
| 97 | { |
||
| 98 | trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->config->set('smilies_per_page_cat', $this->request->variable('smilies_per_page_cat', 15)); |
||
| 102 | |||
| 103 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SC_CONFIG', time()); |
||
| 104 | trigger_error($this->language->lang('CONFIG_UPDATED') . adm_back_link($this->u_action)); |
||
| 105 | |||
| 106 | break; |
||
| 107 | |||
| 108 | case 'add': |
||
| 109 | |||
| 110 | $this->category->adm_add_cat(); |
||
| 111 | |||
| 112 | $this->template->assign_vars(array( |
||
| 113 | 'IN_ADD_ACTION' => true, |
||
| 114 | 'U_BACK' => $this->u_action, |
||
| 115 | 'U_ADD_CAT' => $this->u_action . '&action=add_cat', |
||
| 116 | )); |
||
| 117 | |||
| 118 | break; |
||
| 119 | |||
| 120 | case 'add_cat': |
||
| 121 | |||
| 122 | if (!check_form_key($form_key)) |
||
| 123 | { |
||
| 124 | trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); |
||
| 125 | } |
||
| 126 | |||
| 127 | $cat_order = $this->request->variable('order', 0); |
||
| 128 | $title = $this->request->variable('name_' . $this->user->lang_name, '', true); |
||
| 129 | |||
| 130 | $sql_in = array( |
||
| 131 | 'cat_id' => $this->category->get_max_id() + 1, |
||
| 132 | 'cat_order' => $cat_order, |
||
| 133 | ); |
||
| 134 | |||
| 135 | $sql = 'SELECT lang_id, lang_iso |
||
| 136 | FROM ' . LANG_TABLE . " |
||
| 137 | ORDER BY lang_id ASC"; |
||
| 138 | $result = $this->db->sql_query($sql); |
||
| 139 | while ($row = $this->db->sql_fetchrow($result)) |
||
| 140 | { |
||
| 141 | $iso = $row['lang_iso']; |
||
| 142 | $lang = $this->request->variable("lang_$iso", '', true); |
||
| 143 | $name = $this->request->variable("name_$iso", '', true); |
||
| 144 | if ($name === '') |
||
| 145 | { |
||
| 146 | trigger_error($this->language->lang('SC_CATEGORY_ERROR', $this->language->lang('SC_CATEGORY_NAME')) . adm_back_link($this->u_action . '&action=add'), E_USER_WARNING); |
||
| 147 | } |
||
| 148 | else |
||
| 149 | { |
||
| 150 | $sql_in = array_merge($sql_in, array( |
||
| 151 | 'cat_lang' => $lang, |
||
| 152 | 'cat_name' => $this->category->capitalize($name), |
||
| 153 | 'cat_title' => $this->category->capitalize($title), |
||
| 154 | )); |
||
| 155 | $this->db->sql_query('INSERT INTO ' . $this->smilies_category_table . $this->db->sql_build_array('INSERT', $sql_in)); |
||
| 156 | |||
| 157 | if ($cat_order == 1) |
||
| 158 | { |
||
| 159 | $this->config->set('smilies_category_nb', $sql_in['cat_id']); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SC_' . strtoupper($action), time(), array($title)); |
||
| 165 | trigger_error($this->language->lang('SC_CREATE_SUCCESS') . adm_back_link($this->u_action)); |
||
| 166 | |||
| 167 | break; |
||
| 168 | |||
| 169 | case 'edit': |
||
| 170 | |||
| 171 | $this->category->adm_edit_cat($id); |
||
| 172 | |||
| 173 | $this->template->assign_vars(array( |
||
| 174 | 'U_BACK' => $this->u_action, |
||
| 175 | 'U_EDIT_CAT' => $this->u_action . '&action=edit_cat&id=' . $id, |
||
| 176 | )); |
||
| 177 | |||
| 178 | break; |
||
| 179 | |||
| 180 | case 'edit_cat': |
||
| 181 | |||
| 182 | if (!check_form_key($form_key)) |
||
| 183 | { |
||
| 184 | trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); |
||
| 185 | } |
||
| 186 | |||
| 187 | $title = $this->request->variable('name_' . $this->user->lang_name, '', true); |
||
| 188 | $sql = 'SELECT lang_id, lang_iso |
||
| 189 | FROM ' . LANG_TABLE . " |
||
| 190 | ORDER BY lang_id ASC"; |
||
| 191 | $result = $this->db->sql_query($sql); |
||
| 192 | while ($row = $this->db->sql_fetchrow($result)) |
||
| 193 | { |
||
| 194 | $iso = $row['lang_iso']; |
||
| 195 | $lang = $this->request->variable("lang_$iso", '', true); |
||
| 196 | $name = $this->request->variable("name_$iso", '', true); |
||
| 197 | $sort = $this->request->variable("sort_$iso", ''); |
||
| 198 | $order = $this->request->variable('order', 0); |
||
| 199 | if ($name === '') |
||
| 200 | { |
||
| 201 | trigger_error($this->language->lang('SC_CATEGORY_ERROR', $this->language->lang('SC_CATEGORY_NAME')) . adm_back_link($this->u_action . '&action=edit&id=' . $id), E_USER_WARNING); |
||
| 202 | } |
||
| 203 | else |
||
| 204 | { |
||
| 205 | if ($sort == 'edit') |
||
| 206 | { |
||
| 207 | $sql = 'UPDATE ' . $this->smilies_category_table . " SET cat_name = '" . $this->category->capitalize($name) . "', cat_title = '" . $this->category->capitalize($title) . "' |
||
| 208 | WHERE cat_lang = '" . $this->db->sql_escape($lang) . "' AND cat_id = $id"; |
||
| 209 | $this->db->sql_query($sql); |
||
| 210 | } |
||
| 211 | else if ($sort == 'create') |
||
| 212 | { |
||
| 213 | $sql_in = array( |
||
| 214 | 'cat_id' => $id, |
||
| 215 | 'cat_order' => $order, |
||
| 216 | 'cat_lang' => $lang, |
||
| 217 | 'cat_name' => $this->category->capitalize($name), |
||
| 218 | 'cat_title' => $this->category->capitalize($title), |
||
| 219 | ); |
||
| 220 | $this->db->sql_query('INSERT INTO ' . $this->smilies_category_table . $this->db->sql_build_array('INSERT', $sql_in)); |
||
| 221 | } |
||
| 222 | } |
||
| 223 | } |
||
| 224 | |||
| 225 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SC_' . strtoupper($action), time(), array($title)); |
||
| 226 | trigger_error($this->language->lang('SC_EDIT_SUCCESS') . adm_back_link($this->u_action)); |
||
| 227 | |||
| 228 | break; |
||
| 229 | |||
| 230 | case 'move_up': |
||
| 231 | case 'move_down': |
||
| 232 | |||
| 233 | if (!check_link_hash($this->request->variable('hash', ''), 'acp-main_module')) |
||
| 234 | { |
||
| 235 | trigger_error($this->language->lang('FORM_INVALID') . adm_back_link($this->u_action), E_USER_WARNING); |
||
| 236 | } |
||
| 237 | |||
| 238 | $result = $this->move_cat($action, $id); |
||
| 239 | |||
| 240 | if ($result['return'] === false) |
||
| 241 | { |
||
| 242 | break; |
||
| 243 | } |
||
| 244 | |||
| 245 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_SC_' . strtoupper($action) . '_CAT', time(), array($result['title'])); |
||
| 246 | |||
| 247 | if ($this->request->is_ajax()) |
||
| 248 | { |
||
| 249 | trigger_error($this->language->lang('SC_MOVE_SUCCESS') . adm_back_link($this->u_action)); |
||
| 250 | $json_response = new \phpbb\json_response; |
||
| 251 | $json_response->send(array( |
||
| 252 | 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'), |
||
| 253 | 'MESSAGE_TEXT' => $this->language->lang('SC_MOVE_SUCCESS'), |
||
| 254 | 'REFRESH_DATA' => array('time' => 2), |
||
| 255 | )); |
||
| 256 | } |
||
| 257 | else |
||
| 258 | { |
||
| 259 | trigger_error($this->language->lang('SC_MOVE_SUCCESS') . adm_back_link($this->u_action)); |
||
| 260 | } |
||
| 261 | |||
| 262 | break; |
||
| 263 | |||
| 264 | case 'delete': |
||
| 265 | |||
| 266 | if (confirm_box(true)) |
||
| 267 | { |
||
| 268 | $this->delete_cat($id); |
||
| 269 | |||
| 270 | if ($this->request->is_ajax()) |
||
| 271 | { |
||
| 272 | trigger_error($this->language->lang('SC_DELETE_SUCCESS') . adm_back_link($this->u_action)); |
||
| 273 | $json_response = new \phpbb\json_response; |
||
| 274 | $json_response->send(array( |
||
| 275 | 'MESSAGE_TITLE' => $this->language->lang('INFORMATION'), |
||
| 276 | 'MESSAGE_TEXT' => $this->language->lang('SC_DELETE_SUCCESS'), |
||
| 277 | 'REFRESH_DATA' => array('time' => 2), |
||
| 278 | )); |
||
| 279 | } |
||
| 280 | else |
||
| 281 | { |
||
| 282 | trigger_error($this->language->lang('SC_DELETE_SUCCESS') . adm_back_link($this->u_action)); |
||
| 283 | } |
||
| 284 | } |
||
| 285 | else |
||
| 286 | { |
||
| 287 | confirm_box(false, $this->language->lang('CONFIRM_OPERATION'), build_hidden_fields(array( |
||
| 288 | 'mode' => $mode, |
||
| 289 | 'id' => $id, |
||
| 290 | 'action' => 'delete', |
||
| 291 | ))); |
||
| 292 | } |
||
| 293 | |||
| 294 | break; |
||
| 295 | |||
| 296 | } |
||
| 297 | |||
| 298 | $this->template->assign_vars(array( |
||
| 299 | 'IN_ACTION' => true, |
||
| 300 | )); |
||
| 301 | } |
||
| 302 | else |
||
| 303 | { |
||
| 304 | $this->category->adm_list_cat($this->u_action); |
||
| 305 | } |
||
| 306 | |||
| 307 | $this->template->assign_vars(array( |
||
| 308 | 'CATEGORIE_CONFIG' => true, |
||
| 309 | 'SMILIES_PER_PAGE_CAT' => $this->config['smilies_per_page_cat'], |
||
| 310 | 'U_ADD' => $this->u_action . '&action=add', |
||
| 311 | )); |
||
| 564 |