Conditions | 14 |
Paths | 224 |
Total Lines | 84 |
Code Lines | 49 |
Lines | 8 |
Ratio | 9.52 % |
Tests | 0 |
CRAP Score | 210 |
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 | public function manage_welcome($value, $key, $module_id) |
||
167 | { |
||
168 | $action = ($this->request->is_set_post('reset')) ? 'reset' : ''; |
||
169 | $action = ($this->request->is_set_post('submit')) ? 'save' : $action; |
||
170 | $action = ($this->request->is_set_post('preview')) ? 'preview' : $action; |
||
171 | |||
172 | $portal_config = obtain_portal_config(); |
||
173 | |||
174 | $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 | case 'save': |
||
180 | View Code Duplication | if (!check_form_key('acp_portal')) |
|
181 | { |
||
182 | trigger_error($this->user->lang['FORM_INVALID']. adm_back_link($u_action), E_USER_WARNING); |
||
183 | } |
||
184 | |||
185 | $welcome_message = $this->request->variable('welcome_message', '', true); |
||
186 | $uid = $bitfield = $flags = ''; |
||
187 | 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 | View Code Duplication | if (empty($welcome_message)) |
|
191 | { |
||
192 | 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 | set_portal_config('board3_welcome_message_' . $module_id, $welcome_message); |
||
197 | $this->config->set('board3_welcome_message_uid_' . $module_id, $uid); |
||
198 | $this->config->set('board3_welcome_message_bitfield_' . $module_id, $bitfield); |
||
199 | break; |
||
200 | |||
201 | case 'preview': |
||
202 | $welcome_message = $text = $this->request->variable('welcome_message', '', true); |
||
203 | |||
204 | $bbcode_options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; |
||
205 | $uid = (isset($this->config['board3_welcome_message_uid_' . $module_id])) ? $this->config['board3_welcome_message_uid_' . $module_id] : ''; |
||
206 | $bitfield = (isset($this->config['board3_welcome_message_bitfield_' . $module_id])) ? $this->config['board3_welcome_message_bitfield_' . $module_id] : ''; |
||
207 | $options = OPTION_FLAG_BBCODE + OPTION_FLAG_SMILIES + OPTION_FLAG_LINKS; |
||
208 | generate_text_for_storage($text, $uid, $bitfield, $options, true, true, true); |
||
209 | |||
210 | $text = generate_text_for_display($text, $uid, $bitfield, $options); |
||
211 | |||
212 | $this->template->assign_vars(array( |
||
213 | 'PREVIEW_TEXT' => $text, |
||
214 | 'S_PREVIEW' => true, |
||
215 | )); |
||
216 | |||
217 | // Edit or add menu item |
||
218 | case 'reset': |
||
219 | default: |
||
220 | if (!isset($welcome_message)) |
||
221 | { |
||
222 | $welcome_message = generate_text_for_edit($portal_config['board3_welcome_message_' . $module_id], $this->config['board3_welcome_message_uid_' . $module_id], ''); |
||
223 | } |
||
224 | |||
225 | $this->template->assign_vars(array( |
||
226 | 'WELCOME_MESSAGE' => (is_array($welcome_message)) ? $welcome_message['text'] : $welcome_message, |
||
227 | //'U_BACK' => $u_action, |
||
228 | 'U_ACTION' => $u_action, |
||
229 | 'S_EDIT' => true, |
||
230 | 'S_LINKS_ALLOWED' => true, |
||
231 | 'S_BBCODE_IMG' => true, |
||
232 | 'S_BBCODE_FLASH' => true, |
||
233 | 'S_BBCODE_QUOTE' => true, |
||
234 | 'S_BBCODE_ALLOWED' => true, |
||
235 | 'MAX_FONT_SIZE' => (int) $this->config['max_post_font_size'], |
||
236 | )); |
||
237 | |||
238 | if (!function_exists('display_forums')) |
||
239 | { |
||
240 | include($this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext); |
||
241 | } |
||
242 | |||
243 | // Build custom bbcodes array |
||
244 | display_custom_bbcodes(); |
||
245 | $this->user->add_lang('posting'); |
||
246 | |||
247 | break; |
||
248 | } |
||
249 | } |
||
250 | |||
264 |