Conditions | 15 |
Paths | 73 |
Total Lines | 104 |
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 |
||
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 | if (!$module->login($user_id)) |
||
160 | { |
||
161 | $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_TFA_EXCEPTION',false, ['TFA_INCORRECT_KEY']); |
||
162 | $this->template->assign_var('S_ERROR', $this->user->lang('TFA_INCORRECT_KEY')); |
||
163 | $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect); |
||
164 | } |
||
165 | } |
||
166 | catch (http_exception $ex) // @TODO: Replace exception with own exception |
||
|
|||
167 | { |
||
168 | |||
169 | $this->log->add('critical', $this->user->data['user_id'], $this->user->ip, 'LOG_TFA_EXCEPTION', false, [$ex->getMessage()]); |
||
170 | |||
171 | if ($admin) |
||
172 | { |
||
173 | // Also log it to admin log just to be sure. |
||
174 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_TFA_EXCEPTION', false, [$ex->getMessage()]); |
||
175 | } |
||
176 | if ($ex->getStatusCode() == 400) |
||
177 | { |
||
178 | $this->template->assign_var('S_ERROR', $this->user->lang($ex->getMessage())); |
||
179 | $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect); |
||
180 | } |
||
181 | else |
||
182 | { |
||
183 | throw $ex; |
||
184 | } |
||
185 | } |
||
186 | |||
187 | $old_session_id = $this->user->session_id; |
||
188 | if ($admin) |
||
189 | { |
||
190 | $cookie_expire = time() - 31536000; |
||
191 | $this->user->set_cookie('u', '', $cookie_expire); |
||
192 | $this->user->set_cookie('sid', '', $cookie_expire); |
||
193 | } |
||
194 | $result = $this->user->session_create($user_id, $admin, $auto_login, $viewonline); |
||
195 | |||
196 | // Successful session creation |
||
197 | if ($result === true) |
||
198 | { |
||
199 | // Remove our cookie that causes filling in a key. |
||
200 | $this->user->set_cookie('rn', '', time() + 3600 * 24, true); |
||
201 | // If admin re-authentication we remove the old session entry because a new one has been created... |
||
202 | if ($admin) |
||
203 | { |
||
204 | // the login array is used because the user ids do not differ for re-authentication |
||
205 | $sql = 'DELETE FROM ' . SESSIONS_TABLE . " |
||
206 | WHERE session_id = '" . $this->db->sql_escape($old_session_id) . "' |
||
207 | AND session_user_id = " . (int) $user_id; |
||
208 | $this->db->sql_query($sql); |
||
209 | |||
210 | $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ADMIN_AUTH_SUCCESS'); |
||
211 | |||
212 | redirect(append_sid("{$this->root_path}adm/index.{$this->php_ext}", false, true, $this->user->data['session_id'])); |
||
213 | } |
||
214 | |||
215 | redirect(append_sid($redirect, false, true, $this->user->data['session_id'])); |
||
216 | } |
||
217 | throw new http_exception(400, 'TFA_SOMETHING_WENT_WRONG'); |
||
218 | } |
||
219 | } |
||
220 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.