| Conditions | 7 |
| Paths | 12 |
| Total Lines | 74 |
| Code Lines | 32 |
| 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 |
||
| 17 | public function main($id, $mode) |
||
| 18 | { |
||
| 19 | global $phpbb_container, $request; |
||
| 20 | |||
| 21 | /** @var \phpbb\language\language $language */ |
||
| 22 | $language = $phpbb_container->get('language'); |
||
| 23 | |||
| 24 | // Add the auto groups ACP lang file |
||
| 25 | $language->add_lang('autogroups_acp', 'phpbb/autogroups'); |
||
| 26 | |||
| 27 | // Get an instance of the admin controller |
||
| 28 | $admin_controller = $phpbb_container->get('phpbb.autogroups.admin_controller'); |
||
| 29 | |||
| 30 | // Requests |
||
| 31 | $action = $request->variable('action', ''); |
||
| 32 | $autogroups_id = $request->variable('autogroups_id', 0); |
||
| 33 | |||
| 34 | // Make the $u_action url available in the admin controller |
||
| 35 | $admin_controller->set_page_url($this->u_action); |
||
| 36 | |||
| 37 | // Load a template from adm/style for our ACP auto groups |
||
| 38 | $this->tpl_name = 'manage_autogroups'; |
||
| 39 | |||
| 40 | // Set the page title for our ACP auto groups |
||
| 41 | $this->page_title = $language->lang('ACP_AUTOGROUPS_MANAGE'); |
||
|
|
|||
| 42 | |||
| 43 | // Quick-submit settings from the general options form |
||
| 44 | if ($request->is_set_post('generalsubmit')) |
||
| 45 | { |
||
| 46 | $admin_controller->submit_autogroups_options(); |
||
| 47 | } |
||
| 48 | |||
| 49 | // Perform any actions submitted by the user |
||
| 50 | switch ($action) |
||
| 51 | { |
||
| 52 | case 'add': |
||
| 53 | case 'edit': |
||
| 54 | // Set the page title for our ACP auto groups |
||
| 55 | $this->page_title = $language->lang(strtoupper("ACP_AUTOGROUPS_$action")); |
||
| 56 | |||
| 57 | // Load the save auto group handle in the admin controller |
||
| 58 | $admin_controller->save_autogroup_rule($autogroups_id); |
||
| 59 | |||
| 60 | // Return to stop execution of this script |
||
| 61 | return; |
||
| 62 | break; |
||
| 63 | |||
| 64 | case 'sync': |
||
| 65 | // Resync applies an auto group check against all users |
||
| 66 | $admin_controller->resync_autogroup_rule($autogroups_id); |
||
| 67 | break; |
||
| 68 | |||
| 69 | case 'delete': |
||
| 70 | // Use a confirm box routine when deleting an auto group rule |
||
| 71 | if (confirm_box(true)) |
||
| 72 | { |
||
| 73 | // Delete auto group rule on confirmation from the user |
||
| 74 | $admin_controller->delete_autogroup_rule($autogroups_id); |
||
| 75 | } |
||
| 76 | else |
||
| 77 | { |
||
| 78 | // Request confirmation from the user to delete the auto group rule |
||
| 79 | confirm_box(false, $language->lang('ACP_AUTOGROUPS_DELETE_CONFIRM'), build_hidden_fields(array( |
||
| 80 | 'autogroups_id' => $autogroups_id, |
||
| 81 | 'mode' => $mode, |
||
| 82 | 'action' => $action, |
||
| 83 | ))); |
||
| 84 | } |
||
| 85 | break; |
||
| 86 | } |
||
| 87 | |||
| 88 | // Display auto group rules |
||
| 89 | $admin_controller->display_autogroups(); |
||
| 90 | } |
||
| 91 | } |
||
| 92 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: