Conditions | 9 |
Paths | 16 |
Total Lines | 69 |
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 |
||
136 | private function create_page() |
||
137 | { |
||
138 | $error = array(); |
||
139 | $s_hidden_fields = ''; |
||
140 | |||
141 | add_form_key('ucp_tfa_keys'); |
||
142 | |||
143 | $module_row = $this->request->variable('md', '', true, request_interface::POST); |
||
144 | |||
145 | // Set desired template |
||
146 | $this->tpl_name = 'ucp_tfa'; |
||
147 | $this->page_title = 'UCP_TFA'; |
||
148 | |||
149 | if (!empty($module_row)) |
||
150 | { |
||
151 | switch ($module_row) |
||
152 | { |
||
153 | case $this->user->lang('DELETE_MARKED'): |
||
154 | if (!check_form_key('ucp_tfa_keys')) |
||
155 | { |
||
156 | $error[] = 'FORM_INVALID'; |
||
157 | } |
||
158 | else |
||
159 | { |
||
160 | $this->delete_keys(); |
||
161 | } |
||
162 | break; |
||
163 | |||
164 | case $this->user->lang('TFA_NEW'): |
||
165 | $error = array_merge($this->register_security_key(), $error); |
||
166 | |||
167 | if (!sizeof($error)) |
||
168 | { |
||
169 | return; // register_security_key has its own template stuff, so we return here. |
||
170 | } |
||
171 | break; |
||
172 | |||
173 | } |
||
174 | } |
||
175 | |||
176 | // Replace "error" strings with their real, localised form |
||
177 | $error = array_map(array( |
||
178 | $this->user, |
||
179 | 'lang', |
||
180 | ), $error); |
||
181 | |||
182 | /** |
||
183 | * @var $module_row \paul999\tfa\modules\module_interface |
||
184 | */ |
||
185 | foreach ($this->session_helper->get_modules() as $module_row) |
||
186 | { |
||
187 | $module_row->show_ucp(); |
||
188 | |||
189 | if ($module_row->can_register()) |
||
190 | { |
||
191 | $this->template->assign_block_vars('new_keys', array( |
||
192 | 'CLASS' => $module_row->get_name(), |
||
193 | 'NAME' => $this->user->lang($module_row->get_translatable_name()), |
||
194 | )); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | $this->template->assign_vars(array( |
||
199 | 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '', |
||
200 | 'L_TITLE' => $this->user->lang('UCP_TFA'), |
||
201 | 'S_HIDDEN_FIELDS' => $s_hidden_fields, |
||
202 | 'S_UCP_ACTION' => $this->u_action, |
||
203 | )); |
||
204 | } |
||
205 | |||
232 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.