| Conditions | 21 |
| Paths | 2328 |
| Total Lines | 71 |
| Code Lines | 58 |
| 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 |
||
| 119 | public static function auth() { |
||
| 120 | if (empty($_GET['oauth_verifier']) || empty($_SESSION['oauth_token_secret'])) { |
||
| 121 | $tokens = self::requestToken(); |
||
| 122 | $_SESSION['oauth_token_secret'] = $tokens['oauth_token_secret']; |
||
| 123 | \Inji\Tools::redirect("https://api.twitter.com/oauth/authorize?oauth_token={$tokens['oauth_token']}"); |
||
| 124 | } |
||
| 125 | $verify = self::verify(); |
||
| 126 | |||
| 127 | if (!$verify['user_id']) { |
||
| 128 | \Inji\Tools::redirect('/', 'Не удалось авторизоваться через twitter'); |
||
| 129 | } |
||
| 130 | $userDetail = self::getInfo($verify); |
||
| 131 | |||
| 132 | $social = self::getObject(); |
||
| 133 | $userSocial = \Users\User\Social::get([['uid', $userDetail['id']], ['social_id', $social->id]]); |
||
| 134 | if ($userSocial && $userSocial->user) { |
||
| 135 | \App::$cur->users->newSession($userSocial->user); |
||
| 136 | if (!empty(\App::$cur->users->config['loginUrl'][\App::$cur->type])) { |
||
| 137 | \Inji\Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type]); |
||
| 138 | } |
||
| 139 | } else { |
||
| 140 | if ($userSocial && !$userSocial->user) { |
||
| 141 | $userSocial->delete(); |
||
| 142 | } |
||
| 143 | if (!\Users\User::$cur->id) { |
||
| 144 | $user = new \Users\User(); |
||
| 145 | $user->group_id = 2; |
||
| 146 | $user->role_id = 2; |
||
| 147 | $invite_code = (!empty($_POST['invite_code']) ? $_POST['invite_code'] : ((!empty($_COOKIE['invite_code']) ? $_COOKIE['invite_code'] : ((!empty($_GET['invite_code']) ? $_GET['invite_code'] : ''))))); |
||
| 148 | if (!empty($invite_code)) { |
||
| 149 | $invite = \Users\User\Invite::get($invite_code, 'code'); |
||
| 150 | $inveiteError = false; |
||
| 151 | if (!$invite) { |
||
| 152 | \Inji\Msg::add('Такой код пришлашения не найден', 'danger'); |
||
| 153 | $inveiteError = true; |
||
| 154 | } |
||
| 155 | if ($invite->limit && !($invite->limit - $invite->count)) { |
||
| 156 | \Inji\Msg::add('Лимит приглашений для данного кода исчерпан', 'danger'); |
||
| 157 | $inveiteError = true; |
||
| 158 | } |
||
| 159 | if (!$inveiteError) { |
||
| 160 | $user->parent_id = $invite->user_id; |
||
| 161 | $invite->count++; |
||
| 162 | $invite->save(); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | if (!$user->parent_id && !empty(\App::$cur->Users->config['defaultPartner'])) { |
||
| 166 | $user->parent_id = \App::$cur->Users->config['defaultPartner']; |
||
| 167 | } |
||
| 168 | $user->save(); |
||
| 169 | $userInfo = new \Users\User\Info(); |
||
| 170 | $userInfo->user_id = $user->id; |
||
| 171 | $userInfo->save(); |
||
| 172 | } else { |
||
| 173 | $user = \Users\User::$cur; |
||
| 174 | } |
||
| 175 | $name = explode(' ', $userDetail['name']); |
||
| 176 | $user->info->first_name = $name[0]; |
||
| 177 | $user->info->last_name = $name[1]; |
||
| 178 | $user->info->city = $userDetail['location']; |
||
| 179 | $user->info->save(); |
||
| 180 | $userSocial = new \Users\User\Social(); |
||
| 181 | $userSocial->uid = $userDetail['id']; |
||
| 182 | $userSocial->social_id = $social->id; |
||
| 183 | $userSocial->user_id = $user->id; |
||
| 184 | $userSocial->save(); |
||
| 185 | \App::$cur->users->newSession($user); |
||
| 186 | if (!empty(\App::$cur->users->config['loginUrl'][\App::$cur->type])) { |
||
| 187 | \Inji\Tools::redirect(\App::$cur->users->config['loginUrl'][\App::$cur->type], 'Вы успешно зарегистрировались через Twitter', 'success'); |
||
| 188 | } else { |
||
| 189 | \Inji\Tools::redirect('/users/cabinet/profile', 'Вы успешно зарегистрировались через Twitter', 'success'); |
||
| 190 | } |
||
| 195 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.