| Conditions | 8 |
| Paths | 7 |
| Total Lines | 54 |
| Code Lines | 26 |
| 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 |
||
| 75 | public function handleAccessTokenRequest(TokenEndpoint $tokenEndpoint, array $requestData): array |
||
| 76 | { |
||
| 77 | if (empty($requestData['code'])) { |
||
| 78 | throw new OAuthException('invalid_request', |
||
| 79 | 'The request is missing the required parameter code.', |
||
| 80 | 'https://tools.ietf.org/html/rfc7636#section-4.4'); |
||
| 81 | } |
||
| 82 | $code = $requestData['code']; |
||
| 83 | |||
| 84 | $authorizationCode = $this->authorizationCodeStorage->find($code); |
||
| 85 | |||
| 86 | /** |
||
| 87 | * ensure that the authorization code was issued to the authenticated |
||
| 88 | * confidential client, or if the client is public, ensure that the |
||
| 89 | * code was issued to "client_id" in the request, |
||
| 90 | */ |
||
| 91 | if (!$authorizationCode || $authorizationCode->getClientIdentifier() !== $tokenEndpoint->getClient()->getIdentifier()) { |
||
| 92 | throw new OAuthException('invalid_grant', |
||
| 93 | 'The request includes the invalid parameter code.', |
||
| 94 | 'https://tools.ietf.org/html/rfc7636#section-4.4'); |
||
| 95 | } |
||
| 96 | |||
| 97 | $this->authorizationCodeStorage->revoke($code); |
||
| 98 | |||
| 99 | /** |
||
| 100 | * verify that the authorization code is valid |
||
| 101 | */ |
||
| 102 | if ($this->authorizationCodeStorage->hasExpired($authorizationCode)) { |
||
| 103 | throw new OAuthException('invalid_grant', |
||
| 104 | 'The request includes the invalid parameter code. The code has expired.', |
||
| 105 | 'https://tools.ietf.org/html/rfc7636#section-4.4'); |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * ensure that the "redirect_uri" parameter is present if the |
||
| 110 | * "redirect_uri" parameter was included in the initial authorization |
||
| 111 | * request as described in Section 4.1.1, and if included ensure that |
||
| 112 | * their values are identical. |
||
| 113 | */ |
||
| 114 | if ($authorizationCode->getRedirectUri()) { |
||
| 115 | if (empty($requestData['redirect_uri'])) { |
||
| 116 | throw new OAuthException('invalid_request', |
||
| 117 | 'The request is missing the required parameter redirect_uri', |
||
| 118 | 'https://tools.ietf.org/html/rfc7636#section-4.1'); |
||
| 119 | } |
||
| 120 | if ($requestData['redirect_uri'] !== $authorizationCode->getRedirectUri()) { |
||
| 121 | throw new OAuthException('invalid_request', |
||
| 122 | 'The request includes the invalid parameter redirect_uri', |
||
| 123 | 'https://tools.ietf.org/html/rfc7636#section-4.1'); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | return $this->issueTokens($authorizationCode->getScope(), |
||
| 128 | $authorizationCode->getResourceOwnerIdentifier(), $authorizationCode->getCode()); |
||
| 129 | } |
||
| 130 | } |