| Conditions | 13 | 
| Paths | 35 | 
| Total Lines | 86 | 
| Code Lines | 44 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 19 | ||
| Bugs | 3 | Features | 5 | 
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  | 
            ||
| 109 | public function submit($user_id, $admin, $auto_login, $viewonline, $class)  | 
            ||
| 110 | 	{ | 
            ||
| 111 | 		$this->user->add_lang_ext('paul999/tfa', 'common'); | 
            ||
| 112 | |||
| 113 | 		if (!check_form_key('tfa_login_page')) | 
            ||
| 114 | 		{ | 
            ||
| 115 | 			throw new AccessDeniedHttpException($this->user->lang('FORM_INVALID')); | 
            ||
| 116 | }  | 
            ||
| 117 | |||
| 118 | if (empty($this->user->data['tfa_random']) || $user_id != $this->user->data['tfa_uid'])  | 
            ||
| 119 | 		{ | 
            ||
| 120 | 			throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); | 
            ||
| 121 | }  | 
            ||
| 122 | 		$random = $this->request->variable('random', ''); | 
            ||
| 123 | |||
| 124 | if ($this->user->data['tfa_random'] !== $random || strlen($random) != 40)  | 
            ||
| 125 | 		{ | 
            ||
| 126 | 			throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); | 
            ||
| 127 | }  | 
            ||
| 128 | $sql_ary = array(  | 
            ||
| 129 | 'tfa_random' => '',  | 
            ||
| 130 | 'tfa_uid' => 0,  | 
            ||
| 131 | );  | 
            ||
| 132 | 		$sql = 'UPDATE ' . SESSIONS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sql_ary) . ' | 
            ||
| 133 | WHERE  | 
            ||
| 134 | session_id = \'' . $this->db->sql_escape($this->user->data['session_id']) . '\' AND  | 
            ||
| 135 | session_user_id = ' . (int)$this->user->data['user_id'];  | 
            ||
| 136 | $this->db->sql_query($sql);  | 
            ||
| 137 | |||
| 138 | if (empty($class))  | 
            ||
| 139 | 		{ | 
            ||
| 140 | 			throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); | 
            ||
| 141 | }  | 
            ||
| 142 | |||
| 143 | $module = $this->session_helper->findModule($class);  | 
            ||
| 144 | |||
| 145 | if ($module == null)  | 
            ||
| 146 | 		{ | 
            ||
| 147 | 			throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); | 
            ||
| 148 | }  | 
            ||
| 149 | |||
| 150 | 		$redirect = $this->request->variable('redirect', "{$this->root_path}/index.{$this->php_ext}"); | 
            ||
| 151 | try  | 
            ||
| 152 | 		{ | 
            ||
| 153 | if (!$module->login($user_id))  | 
            ||
| 154 | 			{ | 
            ||
| 155 | 				$this->template->assign_var('S_ERROR', $this->user->lang('TFA_INCORRECT_KEY')); | 
            ||
| 156 | $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect);  | 
            ||
| 157 | }  | 
            ||
| 158 | }  | 
            ||
| 159 | catch (BadRequestHttpException $ex) // @TODO: Replace exception with own exception  | 
            ||
| 160 | 		{ | 
            ||
| 161 | 			$this->template->assign_var('S_ERROR', $ex->getMessage()); | 
            ||
| 162 | $this->session_helper->generate_page($user_id, $admin, $auto_login, $viewonline, $redirect);  | 
            ||
| 163 | }  | 
            ||
| 164 | |||
| 165 | $old_session_id = $this->user->session_id;  | 
            ||
| 166 | |||
| 167 | if ($admin)  | 
            ||
| 168 | 		{ | 
            ||
| 169 | $cookie_expire = time() - 31536000;  | 
            ||
| 170 | 			$this->user->set_cookie('u', '', $cookie_expire); | 
            ||
| 171 | 			$this->user->set_cookie('sid', '', $cookie_expire); | 
            ||
| 172 | }  | 
            ||
| 173 | |||
| 174 | $result = $this->user->session_create($user_id, $admin, $auto_login, $viewonline);  | 
            ||
| 175 | |||
| 176 | // Successful session creation  | 
            ||
| 177 | if ($result === true)  | 
            ||
| 178 | 		{ | 
            ||
| 179 | // If admin re-authentication we remove the old session entry because a new one has been created...  | 
            ||
| 180 | if ($admin)  | 
            ||
| 181 | 			{ | 
            ||
| 182 | // the login array is used because the user ids do not differ for re-authentication  | 
            ||
| 183 | $sql = 'DELETE FROM ' . SESSIONS_TABLE . "  | 
            ||
| 184 | WHERE session_id = '" . $this->db->sql_escape($old_session_id) . "'  | 
            ||
| 185 | AND session_user_id = " . (int) $user_id;  | 
            ||
| 186 | $this->db->sql_query($sql);  | 
            ||
| 187 | |||
| 188 | 				redirect(append_sid("{$this->root_path}adm/index.{$this->php_ext}", false, true, $this->user->data['session_id'])); | 
            ||
| 189 | }  | 
            ||
| 190 | |||
| 191 | redirect(append_sid($redirect, false, true, $this->user->data['session_id']));  | 
            ||
| 192 | }  | 
            ||
| 193 | 		throw new BadRequestHttpException($this->user->lang('TFA_SOMETHING_WENT_WRONG')); | 
            ||
| 194 | }  | 
            ||
| 195 | }  | 
            ||
| 196 |