| Conditions | 10 |
| Paths | 18 |
| Total Lines | 27 |
| Code Lines | 16 |
| 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 |
||
| 53 | public function handle(ServerRequestInterface $request, ResourceOwnerInterface $resourceOwner, |
||
| 54 | RegisteredClient $client, ?array $scope = null, ?array $extendedResponseTypes = null): array |
||
| 55 | { |
||
| 56 | $data = $request->getMethod() === 'GET' ? $request->getQueryParams() : $request->getParsedBody(); |
||
| 57 | |||
| 58 | if (is_array($client->getSupportedGrantTypes()) && !in_array('authorization_code', $client->getSupportedGrantTypes())) { |
||
| 59 | throw new OAuthException('unauthorized_client', |
||
| 60 | 'Client is not authorized to request an authorization code with this method', |
||
| 61 | 'https://tools.ietf.org/html/rfc6749#section-5.2'); |
||
| 62 | } |
||
| 63 | |||
| 64 | $idToken = |
||
| 65 | |||
| 66 | $requestedScopes = $data['scope'] ?? null; |
||
| 67 | $requestedScopes = $requestedScopes ? explode(' ', $requestedScopes) : []; |
||
| 68 | |||
| 69 | $scopeRequestedIsIdentical = true; |
||
| 70 | if ((empty($requestedScopes) && !is_null($scope)) || (is_array($scope) && !empty(array_diff($requestedScopes, $scope)))) { |
||
| 71 | $scopeRequestedIsIdentical = false; |
||
| 72 | } |
||
| 73 | |||
| 74 | $scope = is_array($scope) ? implode(' ', $scope) : null; |
||
| 75 | $authorizationCode = $this->authorizationCodeStorage->create( |
||
| 76 | $client->getIdentifier(), $resourceOwner->getIdentifier(), $idToken, $data['redirect_uri'], $scope, $scopeRequestedIsIdentical); |
||
|
|
|||
| 77 | |||
| 78 | return [ |
||
| 79 | 'code' => $authorizationCode->getCode() |
||
| 80 | ]; |
||
| 130 | } |