| Conditions | 9 | 
| Paths | 8 | 
| Total Lines | 61 | 
| Code Lines | 50 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 4 | ||
| Bugs | 2 | Features | 1 | 
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 | ||
| 35 | public function handleCallback() | ||
| 36 |     { | ||
| 37 |         try { | ||
| 38 |             $github_user=Socialite::driver('github')->user(); | ||
| 39 |         } catch (\Laravel\Socialite\Two\InvalidStateException $e) { | ||
| 40 |             return redirect()->route('home'); | ||
| 41 | } | ||
| 42 | |||
| 43 |         if (Auth::check()) { | ||
| 44 | $user_id=Auth::user()->id; | ||
| 45 |             $ret=UserExtra::search('github_id', $github_user->id); | ||
| 46 |             if (!empty($ret) && $ret[0]['uid']!=$user_id) { | ||
| 47 | $user=User::find($ret[0]['uid']); | ||
| 48 | return $this->generateDuplicateView($user->email); | ||
| 49 | } | ||
| 50 |             Auth::user()->setExtra('github_id', $github_user->id); | ||
| 51 |             Auth::user()->setExtra('github_email', $github_user->email); | ||
| 52 |             Auth::user()->setExtra('github_nickname', $github_user->nickname); | ||
| 53 |             Auth::user()->setExtra('github_homepage', ($github_user->user)['html_url']); | ||
| 54 |             Auth::user()->setExtra('github_token', $github_user->token, 101); | ||
| 55 |             return $this->generateSuccessView(Auth::user()->getExtra('github_email')); | ||
| 56 |         } else { | ||
| 57 |             $ret=UserExtra::search('github_id', $github_user->id); | ||
| 58 |             if (!empty($ret)) { | ||
| 59 | Auth::loginUsingId($ret[0]['uid'], true); | ||
| 60 |                 Auth::user()->setExtra('github_email', $github_user->email); | ||
| 61 |                 Auth::user()->setExtra('github_nickname', $github_user->nickname); | ||
| 62 |                 Auth::user()->setExtra('github_homepage', ($github_user->user)['html_url']); | ||
| 63 |                 Auth::user()->setExtra('github_token', $github_user->token, 101); | ||
| 64 |                 return redirect()->route('account.dashboard'); | ||
| 65 |             } else { | ||
| 66 |                 if (config('app.allow_oauth_temp_account')) { | ||
| 67 |                     try { | ||
| 68 | $createdUser=User::create([ | ||
| 69 | 'name' => Str::random(12), | ||
| 70 | 'email' => Str::random(16)."@temporary.email", | ||
| 71 | 'password' => '', | ||
| 72 | 'avatar' => '/static/img/avatar/default.png', | ||
| 73 | ]); | ||
| 74 |                     } catch (QueryException $exception) { | ||
| 75 | return $this->generateUnknownErrorView(); | ||
| 76 | } | ||
| 77 | Auth::loginUsingId($createdUser->id, true); | ||
| 78 |                     Auth::user()->setExtra('github_id', $github_user->id); | ||
| 79 |                     Auth::user()->setExtra('github_email', $github_user->email); | ||
| 80 |                     Auth::user()->setExtra('github_nickname', $github_user->nickname); | ||
| 81 |                     Auth::user()->setExtra('github_homepage', ($github_user->user)['html_url']); | ||
| 82 |                     Auth::user()->setExtra('github_token', $github_user->token, 101); | ||
| 83 |                     return redirect()->route('account.dashboard'); | ||
| 84 | } | ||
| 85 | $buttons=[[ | ||
| 86 | 'text' => 'login', | ||
| 87 |                     'href' => route('login'), | ||
| 88 | ]]; | ||
| 89 |                 if (config('function.register')) { | ||
| 90 | $buttons[]=[ | ||
| 91 | 'text' => 'register', | ||
| 92 |                         'href' => route('register'), | ||
| 93 | ]; | ||
| 94 | } | ||
| 95 | return $this->generateAccountNotFoundView(); | ||
| 96 | } | ||
| 129 |