| Conditions | 11 |
| Paths | 14 |
| Total Lines | 50 |
| Code Lines | 29 |
| 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 |
||
| 23 | public function handle(Request $request, Closure $next, ...$guards) |
||
| 24 | { |
||
| 25 | foreach($guards as $guard) { |
||
| 26 | if($guard == 'api') { |
||
| 27 | if( |
||
| 28 | !Schema::hasTable('oauth_access_tokens') || |
||
| 29 | !Schema::hasTable('oauth_refresh_tokens') || |
||
| 30 | !Schema::hasTable('oauth_personal_access_clients') || |
||
| 31 | !Schema::hasTable('oauth_clients') || |
||
| 32 | !Schema::hasTable('oauth_auth_codes') |
||
| 33 | ) { |
||
| 34 | throw new \Exception("Please install OAuth2 Server Plugin (plugin link) or Implement OAuth2 Server from this link (https://github.com/Codexshaper/oauth2)", 1); |
||
| 35 | } |
||
| 36 | |||
| 37 | $manager = new Manager; |
||
| 38 | $resourceServer = $manager->getResourceServer(); |
||
| 39 | $psrRequest = ServerRequest::getPsrServerRequest(); |
||
| 40 | |||
| 41 | try { |
||
| 42 | $psr = $resourceServer->validateAuthenticatedRequest($psrRequest); |
||
| 43 | $user_id = $manager->validateUserForRequest($psr); |
||
| 44 | |||
| 45 | if ($user_id) { |
||
| 46 | $user = User::find($user_id); |
||
| 47 | |||
| 48 | $request->merge(['user' => $user ]); |
||
| 49 | $request->merge(['scopes' => $psr->getAttribute('oauth_scopes') ]); |
||
| 50 | |||
| 51 | $request->setUserResolver(function () use ($user) { |
||
| 52 | return $user; |
||
| 53 | }); |
||
| 54 | |||
| 55 | return $next($request); |
||
| 56 | } |
||
| 57 | |||
| 58 | } catch (OAuthServerException $e) { |
||
| 59 | throw new \Exception($e->getMessage()); |
||
| 60 | |||
| 61 | } |
||
| 62 | |||
| 63 | return $next($request); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if(\is_user_logged_in()) { |
||
|
|
|||
| 68 | return $next($request); |
||
| 69 | } |
||
| 70 | |||
| 71 | header('Location: '.\get_site_url().'/wp-admin'); |
||
| 72 | die(); |
||
| 73 | } |
||
| 75 |