Conditions | 15 |
Paths | 59 |
Total Lines | 102 |
Lines | 14 |
Ratio | 13.73 % |
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 |
||
115 | public function submit($user_id, $admin, $auto_login, $viewonline, $class) |
||
116 | { |
||
117 | $this->user->add_lang_ext('paul999/tfa', 'common'); |
||
118 | |||
119 | if (!check_form_key('tfa_login_page')) |
||
120 | { |
||
121 | throw new http_exception(403, 'FORM_INVALID'); |
||
122 | } |
||
123 | |||
124 | if (empty($this->user->data['tfa_random']) || $user_id != $this->user->data['tfa_uid']) |
||
125 | { |
||
126 | throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG'); |
||
127 | } |
||
128 | $random = $this->request->variable('random', ''); |
||
129 | |||
130 | if ($this->user->data['tfa_random'] !== $random || strlen($random) !== 40) |
||
131 | { |
||
132 | throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG'); |
||
133 | } |
||
134 | $sql_ary = array( |
||
135 | 'tfa_random' => '', |
||
136 | 'tfa_uid' => 0, |
||
137 | ); |
||
138 | $sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . " |
||
139 | WHERE |
||
140 | session_id = '" . $this->db->sql_escape($this->user->data['session_id']) . "' AND |
||
141 | session_user_id = " . (int) $this->user->data['user_id']; |
||
142 | $this->db->sql_query($sql); |
||
143 | |||
144 | if (empty($class)) |
||
145 | { |
||
146 | throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG'); |
||
147 | } |
||
148 | |||
149 | $module = $this->session_helper->findModule($class); |
||
150 | |||
151 | if ($module == null) |
||
152 | { |
||
153 | throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG'); |
||
154 | } |
||
155 | |||
156 | $redirect = $this->request->variable('redirect', "{$this->root_path}/index.{$this->php_ext}"); |
||
157 | try |
||
158 | { |
||
159 | View Code Duplication | if (!$module->login($user_id)) |
|
160 | { |
||
161 | $this->template->assign_var('S_ERROR', $this->user->lang('TFA_INCORRECT_KEY')); |
||
162 | $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect); |
||
163 | } |
||
164 | } |
||
165 | catch (http_exception $ex) // @TODO: Replace exception with own exception |
||
166 | { |
||
167 | |||
168 | $this->log->add('error', $this->user->data['user_id'], $this->user->ip, 'LOG_TFA_EXCEPTION', $ex->getMessage()); |
||
169 | |||
170 | if ($admin) { |
||
171 | // Also log it to admin log just to be sure. |
||
172 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_TFA_EXCEPTION', $ex->getMessage()); |
||
173 | } |
||
174 | View Code Duplication | if ($ex->getStatusCode() == 400) |
|
175 | { |
||
176 | $this->template->assign_var('S_ERROR', $this->user->lang($ex->getMessage())); |
||
177 | $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect); |
||
178 | } |
||
179 | else |
||
180 | { |
||
181 | throw $ex; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | $old_session_id = $this->user->session_id; |
||
186 | |||
187 | if ($admin) |
||
188 | { |
||
189 | $cookie_expire = time() - 31536000; |
||
190 | $this->user->set_cookie('u', '', $cookie_expire); |
||
191 | $this->user->set_cookie('sid', '', $cookie_expire); |
||
192 | } |
||
193 | |||
194 | $result = $this->user->session_create($user_id, $admin, $auto_login, $viewonline); |
||
195 | |||
196 | // Successful session creation |
||
197 | if ($result === true) |
||
198 | { |
||
199 | // If admin re-authentication we remove the old session entry because a new one has been created... |
||
200 | if ($admin) |
||
201 | { |
||
202 | // the login array is used because the user ids do not differ for re-authentication |
||
203 | $sql = 'DELETE FROM ' . SESSIONS_TABLE . " |
||
204 | WHERE session_id = '" . $this->db->sql_escape($old_session_id) . "' |
||
205 | AND session_user_id = " . (int) $user_id; |
||
206 | $this->db->sql_query($sql); |
||
207 | |||
208 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ADMIN_AUTH_SUCCESS'); |
||
209 | |||
210 | redirect(append_sid("{$this->root_path}adm/index.{$this->php_ext}", false, true, $this->user->data['session_id'])); |
||
211 | } |
||
212 | |||
213 | redirect(append_sid($redirect, false, true, $this->user->data['session_id'])); |
||
214 | } |
||
215 | throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG'); |
||
216 | } |
||
217 | } |
||
218 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..