| Conditions | 4 |
| Paths | 1 |
| Total Lines | 69 |
| Code Lines | 40 |
| 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 |
||
| 48 | $this->validateRequest($request); |
||
| 49 | $this->validateClient($request); |
||
| 50 | |||
| 51 | // ask for approving this client/scope |
||
| 52 | return new HtmlResponse( |
||
| 53 | $this->tpl->render( |
||
| 54 | 'authorizeOAuthClient', |
||
| 55 | [ |
||
| 56 | 'client_id' => $request->getQueryParameter('client_id'), |
||
| 57 | 'scope' => $request->getQueryParameter('scope'), |
||
| 58 | 'redirect_uri' => $request->getQueryParameter('redirect_uri'), |
||
| 59 | ] |
||
| 60 | ) |
||
| 61 | ); |
||
| 62 | } |
||
| 63 | |||
| 64 | public function postAuthorize(Request $request, $userId) |
||
| 65 | { |
||
| 66 | $this->validateRequest($request); |
||
| 67 | $this->validateClient($request); |
||
| 68 | |||
| 69 | // state is OPTIONAL in remoteStorage specification |
||
| 70 | $state = $request->getQueryParameter('state', false, null); |
||
| 71 | $returnUriPattern = '%s#%s'; |
||
| 72 | |||
| 73 | if ('no' === $request->getPostParameter('approve')) { |
||
| 74 | $redirectParameters = [ |
||
| 75 | 'error' => 'access_denied', |
||
| 76 | 'error_description' => 'user refused authorization', |
||
| 77 | ]; |
||
| 78 | if (!is_null($state)) { |
||
| 79 | $redirectParameters['state'] = $state; |
||
| 80 | } |
||
| 81 | $redirectQuery = http_build_query($redirectParameters); |
||
| 82 | |||
| 83 | $redirectUri = sprintf($returnUriPattern, $request->getQueryParameter('redirect_uri'), $redirectQuery); |
||
| 84 | |||
| 85 | return new RedirectResponse($redirectUri, 302); |
||
| 86 | } |
||
| 87 | |||
| 88 | $accessToken = $this->getAccessToken( |
||
| 89 | $userId, |
||
| 90 | $request->getQueryParameter('client_id'), |
||
| 91 | $request->getQueryParameter('scope') |
||
| 92 | ); |
||
| 93 | |||
| 94 | // add access_token (and optionally state) to redirect_uri |
||
| 95 | $redirectParameters = [ |
||
| 96 | 'access_token' => $accessToken, |
||
| 97 | ]; |
||
| 98 | if (!is_null($state)) { |
||
| 99 | $redirectParameters['state'] = $state; |
||
| 100 | } |
||
| 101 | $redirectQuery = http_build_query($redirectParameters); |
||
| 102 | $redirectUri = sprintf($returnUriPattern, $request->getQueryParameter('redirect_uri'), $redirectQuery); |
||
| 103 | |||
| 104 | return new RedirectResponse($redirectUri, 302); |
||
| 105 | } |
||
| 106 | |||
| 107 | private function getAccessToken($userId, $clientId, $scope) |
||
| 108 | { |
||
| 109 | $existingToken = $this->tokenStorage->getExistingToken( |
||
| 110 | $userId, |
||
| 111 | $clientId, |
||
| 112 | $scope |
||
| 113 | ); |
||
| 114 | |||
| 115 | if (false !== $existingToken) { |
||
| 116 | // if the user already has an access_token for this client and |
||
| 117 | // scope, reuse it |
||
| 186 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.