| Conditions | 7 |
| Paths | 12 |
| Total Lines | 76 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 26 | public function main($id, $mode) |
||
|
|
|||
| 27 | { |
||
| 28 | global $phpbb_container; |
||
| 29 | |||
| 30 | /** @var \phpbb\language\language $language */ |
||
| 31 | $language = $phpbb_container->get('language'); |
||
| 32 | |||
| 33 | /** @var \phpbb\request\request $request */ |
||
| 34 | $request = $phpbb_container->get('request'); |
||
| 35 | |||
| 36 | // Add the auto groups ACP lang file |
||
| 37 | $language->add_lang('autogroups_acp', 'phpbb/autogroups'); |
||
| 38 | |||
| 39 | // Get an instance of the admin controller |
||
| 40 | $admin_controller = $phpbb_container->get('phpbb.autogroups.admin_controller'); |
||
| 41 | |||
| 42 | // Requests |
||
| 43 | $action = $request->variable('action', ''); |
||
| 44 | $autogroups_id = $request->variable('autogroups_id', 0); |
||
| 45 | |||
| 46 | // Make the $u_action url available in the admin controller |
||
| 47 | $admin_controller->set_page_url($this->u_action); |
||
| 48 | |||
| 49 | // Load a template from adm/style for our ACP auto groups |
||
| 50 | $this->tpl_name = 'manage_autogroups'; |
||
| 51 | |||
| 52 | // Set the page title for our ACP auto groups |
||
| 53 | $this->page_title = 'ACP_AUTOGROUPS_MANAGE'; |
||
| 54 | |||
| 55 | // Quick-submit settings from the general options form |
||
| 56 | if ($request->is_set_post('generalsubmit')) |
||
| 57 | { |
||
| 58 | $admin_controller->submit_autogroups_options(); |
||
| 59 | } |
||
| 60 | |||
| 61 | // Perform any actions submitted by the user |
||
| 62 | switch ($action) |
||
| 63 | { |
||
| 64 | case 'add': |
||
| 65 | case 'edit': |
||
| 66 | // Set the page title for our ACP auto groups |
||
| 67 | $this->page_title = strtoupper("ACP_AUTOGROUPS_$action"); |
||
| 68 | |||
| 69 | // Load the save auto group handle in the admin controller |
||
| 70 | $admin_controller->save_autogroup_rule($autogroups_id); |
||
| 71 | |||
| 72 | // Return to stop execution of this script |
||
| 73 | return; |
||
| 74 | break; |
||
| 75 | |||
| 76 | case 'sync': |
||
| 77 | // Resync applies an auto group check against all users |
||
| 78 | $admin_controller->resync_autogroup_rule($autogroups_id); |
||
| 79 | break; |
||
| 80 | |||
| 81 | case 'delete': |
||
| 82 | // Use a confirm box routine when deleting an auto group rule |
||
| 83 | if (confirm_box(true)) |
||
| 84 | { |
||
| 85 | // Delete auto group rule on confirmation from the user |
||
| 86 | $admin_controller->delete_autogroup_rule($autogroups_id); |
||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | // Request confirmation from the user to delete the auto group rule |
||
| 91 | confirm_box(false, $language->lang('ACP_AUTOGROUPS_DELETE_CONFIRM'), build_hidden_fields(array( |
||
| 92 | 'autogroups_id' => $autogroups_id, |
||
| 93 | 'mode' => $mode, |
||
| 94 | 'action' => $action, |
||
| 95 | ))); |
||
| 96 | } |
||
| 97 | break; |
||
| 98 | } |
||
| 99 | |||
| 100 | // Display auto group rules |
||
| 101 | $admin_controller->display_autogroups(); |
||
| 102 | } |
||
| 104 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.