| Conditions | 5 |
| Paths | 4 |
| Total Lines | 69 |
| Code Lines | 52 |
| 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 |
||
| 41 | public function handleCallback() |
||
| 42 | { |
||
| 43 | $github_user = Socialite::driver('github')->user(); |
||
| 44 | $accountModel = new AccountModel(); |
||
| 45 | |||
| 46 | if(Auth::check()){ |
||
| 47 | $user_id = Auth::user()->id; |
||
| 48 | $ret = $accountModel->findExtra('github_id',$github_user->id); |
||
| 49 | if(!empty($ret) && $ret['uid'] != $user_id){ |
||
| 50 | $user = UserModel::find($ret['uid']); |
||
| 51 | return view('oauth.index',[ |
||
| 52 | 'page_title'=>"OAuth", |
||
| 53 | 'site_title'=>"NOJ", |
||
| 54 | 'navigation'=>"OAuth", |
||
| 55 | 'platform' => 'Github', |
||
| 56 | 'display_html' => 'The github account is now tied to another NOJ account : <span class="text-danger">'.$user->email.'</span><br /> |
||
| 57 | You can try logging in using github', |
||
| 58 | 'buttons' => [ |
||
| 59 | [ |
||
| 60 | 'text' => 'home', |
||
| 61 | 'href' => route('home'), |
||
| 62 | ], |
||
| 63 | ] |
||
| 64 | ]); |
||
| 65 | } |
||
| 66 | $accountModel->setExtra($user_id,'github_id',$github_user->id); |
||
| 67 | $accountModel->setExtra($user_id,'github_email',$github_user->email); |
||
| 68 | $accountModel->setExtra($user_id,'github_nickname',$github_user->nickname); |
||
| 69 | $accountModel->setExtra($user_id,'github_homepage',($github_user->user)['html_url']); |
||
| 70 | $accountModel->setExtra($user_id,'github_token',$github_user->token,101); |
||
| 71 | return view('oauth.index',[ |
||
| 72 | 'page_title'=>"OAuth", |
||
| 73 | 'site_title'=>"NOJ", |
||
| 74 | 'navigation'=>"OAuth", |
||
| 75 | 'platform' => 'Github', |
||
| 76 | 'display_html' => 'You have successfully tied up the github account : <span class="text-info">'.$accountModel->getExtra(Auth::user()->id ,'github_email').'</span><br /> |
||
| 77 | You can log in to NOJ later using this account', |
||
| 78 | 'buttons' => [ |
||
| 79 | [ |
||
| 80 | 'text' => 'home', |
||
| 81 | 'href' => route('home'), |
||
| 82 | ], |
||
| 83 | ] |
||
| 84 | ]); |
||
| 85 | }else{ |
||
| 86 | $ret = $accountModel->findExtra('github_id',$github_user->id); |
||
| 87 | if(!empty($ret)){ |
||
| 88 | $github_user = Socialite::driver('github')->user(); |
||
| 89 | Auth::loginUsingId($ret['uid']); |
||
| 90 | $accountModel->setExtra($user_id,'github_email',$github_user->email); |
||
| 91 | $accountModel->setExtra($user_id,'github_nickname',$github_user->nickname); |
||
| 92 | $accountModel->setExtra($user_id,'github_homepage',($github_user->user)['html_url']); |
||
| 93 | $accountModel->setExtra($user_id,'github_token',$github_user->token,101); |
||
| 94 | return redirect('/'); |
||
| 95 | }else{ |
||
| 96 | return view('oauth.index',[ |
||
| 97 | 'page_title'=>"OAuth", |
||
| 98 | 'site_title'=>"NOJ", |
||
| 99 | 'navigation'=>"OAuth", |
||
| 100 | 'platform' => 'Github', |
||
| 101 | 'display_text' => 'This github account doesn\'t seem to have a NOJ account, please register or log in first', |
||
| 102 | 'buttons' => [ |
||
| 103 | [ |
||
| 104 | 'text' => 'login', |
||
| 105 | 'href' => route('login'), |
||
| 106 | ], |
||
| 107 | [ |
||
| 108 | 'text' => 'register', |
||
| 109 | 'href' => route('register'), |
||
| 110 | ], |
||
| 200 |