Conditions | 11 |
Paths | 14 |
Total Lines | 49 |
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 |
||
39 | public function handle(Request $request, Closure $next, ...$guards) |
||
40 | { |
||
41 | foreach ($guards as $guard) { |
||
42 | if ($guard == 'api') { |
||
43 | if (!Schema::hasTable('oauth_access_tokens') || |
||
44 | !Schema::hasTable('oauth_refresh_tokens') || |
||
45 | !Schema::hasTable('oauth_personal_access_clients') || |
||
46 | !Schema::hasTable('oauth_clients') || |
||
47 | !Schema::hasTable('oauth_auth_codes') |
||
48 | ) { |
||
49 | throw new \Exception('Please install OAuth2 Server Plugin (plugin link) or Implement OAuth2 Server from this link (https://github.com/Codexshaper/oauth2)', 1); |
||
50 | } |
||
51 | |||
52 | $manager = new Manager(); |
||
53 | $resource_server = $manager->getResourceServer(); |
||
54 | $psr_request = ServerRequest::getPsrServerRequest(); |
||
55 | |||
56 | try { |
||
57 | $psr = $resource_server->validateAuthenticatedRequest($psr_request); |
||
58 | $user_id = $manager->validateUserForRequest($psr); |
||
59 | |||
60 | if ($user_id) { |
||
61 | $user = User::find($user_id); |
||
62 | |||
63 | $request->merge(['user' => $user]); |
||
64 | $request->merge(['scopes' => $psr->getAttribute('oauth_scopes')]); |
||
65 | |||
66 | $request->setUserResolver( |
||
67 | function () use ($user) { |
||
68 | return $user; |
||
69 | } |
||
70 | ); |
||
71 | |||
72 | return $next($request); |
||
73 | } |
||
74 | } catch (OAuthServerException $e) { |
||
75 | throw new \Exception($e->getMessage()); |
||
76 | } |
||
77 | |||
78 | return $next($request); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | if (\is_user_logged_in()) { |
||
|
|||
83 | return $next($request); |
||
84 | } |
||
85 | |||
86 | header('Location: '.\get_site_url().'/wp-admin'); |
||
87 | die(); |
||
88 | } |
||
90 |