Conditions | 22 |
Paths | 58 |
Total Lines | 162 |
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 |
||
26 | public function main($id, $mode) |
||
27 | { |
||
28 | global $request, $phpbb_container; |
||
29 | |||
30 | $action = $request->variable('action', ''); |
||
31 | $update = ($request->is_set_post('update')) ? true : false; |
||
32 | |||
33 | switch ($mode) |
||
34 | { |
||
35 | case 'main': |
||
36 | |||
37 | // Set the page title for our ACP page |
||
38 | $this->page_title = 'ACP_DIRECTORY'; |
||
39 | |||
40 | // Load a template from adm/style for our ACP page |
||
41 | $this->tpl_name = 'acp_dir_main'; |
||
42 | |||
43 | // Get an instance of the acp_main controller |
||
44 | $main_controller = $phpbb_container->get('ernadoo.phpbbdirectory.controller.acp.main'); |
||
45 | |||
46 | // Make the $u_action url available in the acp_main controller |
||
47 | $main_controller->set_page_url($this->u_action); |
||
48 | |||
49 | if ($action) |
||
50 | { |
||
51 | if (!confirm_box(true)) |
||
52 | { |
||
53 | $main_controller->display_confirm($action); |
||
54 | } |
||
55 | else |
||
56 | { |
||
57 | $main_controller->exec_action($action); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | // Display main page |
||
62 | $main_controller->display_stats(); |
||
63 | |||
64 | break; |
||
65 | |||
66 | case 'settings': |
||
67 | |||
68 | // Get an instance of the acp_settings controller |
||
69 | $settings_controller = $phpbb_container->get('ernadoo.phpbbdirectory.controller.acp.settings'); |
||
70 | |||
71 | // Set the page title for our ACP page |
||
72 | $this->page_title = 'ACP_DIRECTORY_SETTINGS'; |
||
73 | |||
74 | // Load a template from adm/style for our ACP page |
||
75 | $this->tpl_name = 'acp_board'; |
||
76 | |||
77 | // Make the $u_action url available in the acp_settings controller |
||
78 | $settings_controller->set_page_url($this->u_action); |
||
79 | |||
80 | $settings_controller->process(); |
||
81 | |||
82 | // Display config |
||
83 | $settings_controller->display_config(); |
||
84 | |||
85 | break; |
||
86 | |||
87 | case 'cat': |
||
88 | |||
89 | // Set the page title for our ACP page |
||
90 | $this->page_title = 'ACP_DIRECTORY'; |
||
91 | |||
92 | // Load a template from adm/style for our ACP page |
||
93 | $this->tpl_name = 'acp_dir_cat'; |
||
94 | |||
95 | // Get an instance of the acp_cat controller |
||
96 | $cat_controller = $phpbb_container->get('ernadoo.phpbbdirectory.controller.acp.cat'); |
||
97 | |||
98 | // Make the $u_action url available in the acp_cat controller |
||
99 | $cat_controller->set_page_url($this->u_action); |
||
100 | |||
101 | // Major routines |
||
102 | if ($update) |
||
103 | { |
||
104 | $cat_controller->update(); |
||
105 | } |
||
106 | |||
107 | switch ($action) |
||
108 | { |
||
109 | case 'progress_bar': |
||
110 | $cat_controller->action_progress_bar(); |
||
111 | return; |
||
112 | break; |
||
113 | |||
114 | case 'sync': |
||
115 | $cat_controller->action_sync(); |
||
116 | break; |
||
117 | |||
118 | case 'sync_cat': |
||
119 | $cat_controller->action_sync_cat(); |
||
120 | break; |
||
121 | |||
122 | case 'move_up': |
||
123 | case 'move_down': |
||
124 | $cat_controller->action_move(); |
||
125 | break; |
||
126 | |||
127 | case 'edit': |
||
128 | $this->page_title = 'DIR_EDIT_CAT'; |
||
129 | |||
130 | $cat_controller->action_edit(); |
||
131 | return; |
||
132 | break; |
||
133 | |||
134 | case 'add': |
||
135 | $this->page_title = 'DIR_ADD_CAT'; |
||
136 | |||
137 | $cat_controller->action_add(); |
||
138 | return; |
||
139 | break; |
||
140 | |||
141 | case 'delete': |
||
142 | $cat_controller->action_delete(); |
||
143 | return; |
||
144 | break; |
||
145 | } |
||
146 | |||
147 | // Display categories |
||
148 | $cat_controller->display_cats(); |
||
149 | |||
150 | break; |
||
151 | |||
152 | case 'val': |
||
153 | |||
154 | // Set the page title for our ACP page |
||
155 | $this->page_title = 'ACP_DIRECTORY'; |
||
156 | |||
157 | // Load a template from adm/style for our ACP page |
||
158 | $this->tpl_name = 'acp_dir_val'; |
||
159 | |||
160 | // Get an instance of the acp_validation controller |
||
161 | $validation_controller = $phpbb_container->get('ernadoo.phpbbdirectory.controller.acp.validation'); |
||
162 | |||
163 | // Make the $u_action url available in the acp_validation controller |
||
164 | $validation_controller->set_page_url($this->u_action); |
||
165 | |||
166 | $mark = ($request->is_set_post('link_id')) ? $request->variable('link_id', array(0)) : array(); |
||
167 | |||
168 | if ($action && count($mark)) |
||
169 | { |
||
170 | if (!confirm_box(true) && $action != 'approved') |
||
171 | { |
||
172 | $validation_controller->display_confirm($mark); |
||
173 | } |
||
174 | else |
||
175 | { |
||
176 | $validation_controller->exec_action($mark); |
||
177 | } |
||
178 | |||
179 | $validation_controller->notifiy_submiters(); |
||
180 | } |
||
181 | |||
182 | // Display websites pending validation |
||
183 | $validation_controller->display_websites(); |
||
184 | |||
185 | break; |
||
186 | } |
||
187 | } |
||
188 | |||
260 |