Conditions | 14 |
Paths | 224 |
Total Lines | 84 |
Code Lines | 49 |
Lines | 8 |
Ratio | 9.52 % |
Tests | 58 |
CRAP Score | 14.0072 |
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 |
||
166 | 3 | public function manage_welcome($value, $key, $module_id) |
|
167 | { |
||
168 | 3 | $action = ($this->request->is_set_post('reset')) ? 'reset' : ''; |
|
169 | 3 | $action = ($this->request->is_set_post('submit')) ? 'save' : $action; |
|
170 | 3 | $action = ($this->request->is_set_post('preview')) ? 'preview' : $action; |
|
171 | |||
172 | 3 | $portal_config = obtain_portal_config(); |
|
173 | |||
174 | 3 | $u_action = append_sid('index.' . $this->php_ext, 'i=-board3-portal-acp-portal_module&mode=config&module_id=' . $module_id); |
|
175 | |||
176 | switch ($action) |
||
177 | { |
||
178 | // Save changes |
||
179 | 3 | case 'save': |
|
180 | 3 | View Code Duplication | if (!check_form_key('acp_portal')) |
181 | 3 | { |
|
182 | 1 | trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING); |
|
183 | } |
||
184 | |||
185 | 2 | $welcome_message = $this->request->variable('welcome_message', '', true); |
|
186 | 2 | $uid = $bitfield = $flags = ''; |
|
187 | 2 | generate_text_for_storage($welcome_message, $uid, $bitfield, $flags, true, true, true); |
|
188 | |||
189 | // first check for obvious errors, we don't want to waste server resources |
||
190 | 2 | View Code Duplication | if (empty($welcome_message)) |
191 | 2 | { |
|
192 | 1 | trigger_error($this->user->lang['ACP_PORTAL_WELCOME_MESSAGE_SHORT']. adm_back_link($u_action), E_USER_WARNING); |
|
193 | } |
||
194 | |||
195 | // set_portal_config will take care of escaping the welcome message |
||
196 | 1 | set_portal_config('board3_welcome_message_' . $module_id, $welcome_message); |
|
197 | 1 | $this->config->set('board3_welcome_message_uid_' . $module_id, $uid); |
|
198 | 1 | $this->config->set('board3_welcome_message_bitfield_' . $module_id, $bitfield); |
|
199 | 1 | break; |
|
200 | |||
201 | 1 | case 'preview': |
|
202 | 1 | $welcome_message = $text = $this->request->variable('welcome_message', '', true); |
|
203 | |||
204 | 1 | $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; |
|
205 | 1 | $uid = (isset($this->config['board3_welcome_message_uid_' . $module_id])) ? $this->config['board3_welcome_message_uid_' . $module_id] : ''; |
|
206 | 1 | $bitfield = (isset($this->config['board3_welcome_message_bitfield_' . $module_id])) ? $this->config['board3_welcome_message_bitfield_' . $module_id] : ''; |
|
207 | 1 | $options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; |
|
208 | 1 | generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true); |
|
209 | |||
210 | 1 | $text = generate_text_for_display($text, $uid, $bitfield, $options); |
|
211 | |||
212 | 1 | $this->template->assign_vars(array( |
|
213 | 1 | 'PREVIEW_TEXT' => $text, |
|
214 | 1 | 'S_PREVIEW' => true, |
|
215 | 1 | )); |
|
216 | |||
217 | // Edit or add menu item |
||
218 | 1 | case 'reset': |
|
219 | 1 | default: |
|
220 | 1 | if (!isset($welcome_message)) |
|
221 | 1 | { |
|
222 | 1 | $welcome_message = generate_text_for_edit($portal_config['board3_welcome_message_' . $module_id], $this->config['board3_welcome_message_uid_' . $module_id], ''); |
|
223 | 1 | } |
|
224 | |||
225 | 1 | $this->template->assign_vars(array( |
|
226 | 1 | 'WELCOME_MESSAGE' => (is_array($welcome_message)) ? $welcome_message['text'] : $welcome_message, |
|
227 | //'U_BACK' => $u_action, |
||
228 | 1 | 'U_ACTION' => $u_action, |
|
229 | 1 | 'S_EDIT' => true, |
|
230 | 1 | 'S_LINKS_ALLOWED' => true, |
|
231 | 1 | 'S_BBCODE_IMG' => true, |
|
232 | 1 | 'S_BBCODE_FLASH' => true, |
|
233 | 1 | 'S_BBCODE_QUOTE' => true, |
|
234 | 1 | 'S_BBCODE_ALLOWED' => true, |
|
235 | 1 | 'MAX_FONT_SIZE' => (int) $this->config['max_post_font_size'], |
|
236 | 1 | )); |
|
237 | |||
238 | 1 | if (!function_exists('display_forums')) |
|
239 | 1 | { |
|
240 | 1 | include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); |
|
241 | 1 | } |
|
242 | |||
243 | // Build custom bbcodes array |
||
244 | 1 | display_custom_bbcodes(); |
|
245 | 1 | $this->user->add_lang('posting'); |
|
246 | |||
247 | 1 | break; |
|
248 | 1 | } |
|
249 | 1 | } |
|
250 | |||
264 |