Completed
Pull Request — master (#122)
by Matt
04:11 queued 37s
created

autogroups_module::main()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 74
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 6.6374
c 0
b 0
f 0
cc 7
eloc 32
nc 12
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
*
4
* Auto Groups extension for the phpBB Forum Software package.
5
*
6
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace phpbb\autogroups\acp;
12
13
class autogroups_module
14
{
15
	public $u_action;
16
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');
0 ignored issues
show
Bug introduced by
The property page_title does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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