| Conditions | 5 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 28 |
| 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 |
||
| 33 | { |
||
| 34 | $providerUser = Socialite::driver($provider)->user(); |
||
| 35 | dd($providerUser); |
||
| 36 | // @TODO |
||
|
|
|||
| 37 | switch ($provider) { |
||
| 38 | case 'github': |
||
| 39 | $asd = 'asd'; |
||
| 40 | break; |
||
| 41 | } |
||
| 42 | |||
| 43 | $attributes = [ |
||
| 44 | 'id' => $providerUser->id, |
||
| 45 | 'email' => $providerUser->email, |
||
| 46 | 'username' => $providerUser->nickname, |
||
| 47 | 'last_token' => $providerUser->token, |
||
| 48 | ]; |
||
| 49 | |||
| 50 | if (! ($localUser = $this->getLocalUser($provider, $providerUser->id))) { |
||
| 51 | $localUser = $this->createLocalUser($provider, $attributes); |
||
| 52 | } |
||
| 53 | |||
| 54 | $loginResult = auth()->guard($this->getGuard())->attempt([ |
||
| 55 | 'is_active' => $localUser->is_active, |
||
| 56 | 'email' => $localUser->email, |
||
| 57 | 'social' => true, |
||
| 58 | ], true); |
||
| 59 | |||
| 60 | return $this->getLoginResponse(request(), $loginResult); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get local user for the given provider. |
||
| 65 | * |
||
| 66 | * @param string $provider |
||
| 67 | * @param int $providerUserId |
||
| 68 | * |
||
| 69 | * @return \Illuminate\Database\Eloquent\Model|null |
||
| 70 | */ |
||
| 71 | protected function getLocalUser(string $provider, int $providerUserId) |
||
| 72 | { |
||
| 73 | return app('rinvex.fort.user')->whereHas('socialites', function (Builder $builder) use ($provider, $providerUserId) { |
||
| 74 | $builder->where('provider', $provider)->where('provider_uid', $providerUserId); |
||
| 75 | })->first(); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Create local user for the given provider. |
||
| 80 | * |
||
| 81 | * @param string $provider |
||
| 82 | * @param array $attributes |
||
| 83 | * |
||
| 84 | * @return \Illuminate\Database\Eloquent\Model|null |
||
| 112 |
This check looks
TODOcomments that have been left in the code.``TODO``s show that something is left unfinished and should be attended to.