| Conditions | 21 |
| Paths | 896 |
| Total Lines | 142 |
| 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 |
||
| 29 | public function main($id, $mode) |
||
| 30 | { |
||
| 31 | global $user, $template, $request; |
||
| 32 | global $config, $phpbb_dispatcher, $phpbb_log; |
||
| 33 | |||
| 34 | $user->add_lang_ext('paul999/tfa', 'acp_tfa'); |
||
| 35 | $user->add_lang('acp/board'); |
||
| 36 | |||
| 37 | $submit = $request->is_set('submit'); |
||
| 38 | |||
| 39 | $form_key = 'acp_tfa'; |
||
| 40 | add_form_key($form_key); |
||
| 41 | |||
| 42 | $display_vars = array( |
||
| 43 | 'title' => 'ACP_TFA_SETTINGS', |
||
| 44 | 'vars' => array( |
||
| 45 | 'legend1' => 'ACP_TFA_SETTINGS', |
||
| 46 | 'tfa_mode' => array('lang' => 'TFA_MODE', 'validate' => 'int', 'type' => 'select', 'method' => 'select_tfa_method', 'explain' => true), |
||
| 47 | 'tfa_acp' => array('lang' => 'TFA_ACP', 'validate' => 'int', 'type' => 'radio:no_yes', 'explain' => true), |
||
| 48 | |||
| 49 | 'legend4' => 'ACP_SUBMIT_CHANGES', |
||
| 50 | ) |
||
| 51 | ); |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Event to add and/or modify acp_board configurations |
||
| 55 | * |
||
| 56 | * @event paul999.tfa.tfa_config_edit_add |
||
| 57 | * @var array display_vars Array of config values to display and process |
||
| 58 | * @var string mode Mode of the config page we are displaying |
||
| 59 | * @var boolean submit Do we display the form or process the submission |
||
| 60 | * @since 1.0.0-b2 |
||
| 61 | */ |
||
| 62 | $vars = array('display_vars', 'mode', 'submit'); |
||
| 63 | extract($phpbb_dispatcher->trigger_event('paul999.tfa.tfa_config_edit_add', compact($vars))); |
||
|
|
|||
| 64 | |||
| 65 | $this->new_config = $config; |
||
| 66 | // Copied from acp_board.php |
||
| 67 | $cfg_array = ($request->is_set('config')) ? $request->variable('config', array('' => ''), true) : $this->new_config; |
||
| 68 | $error = array(); |
||
| 69 | |||
| 70 | // We validate the complete config if wished |
||
| 71 | validate_config_vars($display_vars['vars'], $cfg_array, $error); |
||
| 72 | |||
| 73 | if ($submit && !check_form_key($form_key)) |
||
| 74 | { |
||
| 75 | $error[] = $user->lang('FORM_INVALID'); |
||
| 76 | } |
||
| 77 | // Do not write values if there is an error |
||
| 78 | if (sizeof($error)) |
||
| 79 | { |
||
| 80 | $submit = false; |
||
| 81 | } |
||
| 82 | |||
| 83 | // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to... |
||
| 84 | foreach ($display_vars['vars'] as $config_name => $null) |
||
| 85 | { |
||
| 86 | if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) |
||
| 87 | { |
||
| 88 | continue; |
||
| 89 | } |
||
| 90 | |||
| 91 | $this->new_config[$config_name] = $config_value = $cfg_array[$config_name]; |
||
| 92 | |||
| 93 | if ($submit) |
||
| 94 | { |
||
| 95 | $config->set($config_name, $config_value); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($submit) |
||
| 100 | { |
||
| 101 | $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_TFA_CONFIG_' . strtoupper($mode)); |
||
| 102 | |||
| 103 | $message = $user->lang('CONFIG_UPDATED'); |
||
| 104 | $message_type = E_USER_NOTICE; |
||
| 105 | |||
| 106 | trigger_error($message . adm_back_link($this->u_action), $message_type); |
||
| 107 | } |
||
| 108 | |||
| 109 | if (!$request->is_secure()) |
||
| 110 | { |
||
| 111 | $error[] = $user->lang('TFA_REQUIRES_SSL'); |
||
| 112 | } |
||
| 113 | |||
| 114 | $this->tpl_name = 'acp_board'; |
||
| 115 | $this->page_title = $display_vars['title']; |
||
| 116 | |||
| 117 | $template->assign_vars(array( |
||
| 118 | 'L_TITLE' => $user->lang($display_vars['title']), |
||
| 119 | 'L_TITLE_EXPLAIN' => $user->lang($display_vars['title'] . '_EXPLAIN'), |
||
| 120 | |||
| 121 | 'S_ERROR' => (sizeof($error)) ? true : false, |
||
| 122 | 'ERROR_MSG' => implode('<br />', $error), |
||
| 123 | |||
| 124 | 'U_ACTION' => $this->u_action, |
||
| 125 | )); |
||
| 126 | |||
| 127 | // Output relevant page |
||
| 128 | foreach ($display_vars['vars'] as $config_key => $vars) |
||
| 129 | { |
||
| 130 | if (!is_array($vars) && strpos($config_key, 'legend') === false) |
||
| 131 | { |
||
| 132 | continue; |
||
| 133 | } |
||
| 134 | |||
| 135 | if (strpos($config_key, 'legend') !== false) |
||
| 136 | { |
||
| 137 | $template->assign_block_vars('options', array( |
||
| 138 | 'S_LEGEND' => true, |
||
| 139 | 'LEGEND' => array_key_exists($vars, $user->lang) ? $user->lang($vars) : $vars, |
||
| 140 | )); |
||
| 141 | |||
| 142 | continue; |
||
| 143 | } |
||
| 144 | |||
| 145 | $type = explode(':', $vars['type']); |
||
| 146 | |||
| 147 | $l_explain = ''; |
||
| 148 | if ($vars['explain'] && array_key_exists($vars['lang'] . '_EXPLAIN', $user->lang)) |
||
| 149 | { |
||
| 150 | $l_explain = $user->lang($vars['lang'] . '_EXPLAIN'); |
||
| 151 | } |
||
| 152 | |||
| 153 | $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars); |
||
| 154 | |||
| 155 | if (empty($content)) |
||
| 156 | { |
||
| 157 | continue; |
||
| 158 | } |
||
| 159 | |||
| 160 | $template->assign_block_vars('options', array( |
||
| 161 | 'KEY' => $config_key, |
||
| 162 | 'TITLE' => (array_key_exists($vars['lang'], $user->lang)) ? $user->lang($vars['lang']) : $vars['lang'], |
||
| 163 | 'S_EXPLAIN' => $vars['explain'], |
||
| 164 | 'TITLE_EXPLAIN' => $l_explain, |
||
| 165 | 'CONTENT' => $content, |
||
| 166 | )); |
||
| 167 | |||
| 168 | unset($display_vars['vars'][$config_key]); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 195 |