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