| Conditions | 12 |
| Paths | 82 |
| Total Lines | 52 |
| Code Lines | 38 |
| 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 |
||
| 91 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
| 92 | { |
||
| 93 | try { |
||
| 94 | $authorization = $this->createAuthorizationFromRequest($request); |
||
| 95 | $isFullyAuthenticated = null; |
||
| 96 | $userAccount = $this->userAccountDiscovery->find($isFullyAuthenticated); |
||
| 97 | if (null === $authorization->getUserAccount()) { |
||
| 98 | return $this->redirectToLoginPage($request, $authorization); |
||
| 99 | } |
||
| 100 | $authorization = $authorization->withUserAccount($userAccount, $isFullyAuthenticated); |
||
| 101 | $this->userAccountCheckerManager->check($authorization); |
||
| 102 | $authorization = $this->consentScreenExtensionManager->processBefore($request, $authorization); |
||
| 103 | |||
| 104 | return $this->processConsentScreen($request, $authorization); |
||
| 105 | } catch (OAuth2AuthorizationException $e) { |
||
| 106 | $data = $e->getData(); |
||
| 107 | if (null !== $e->getAuthorization()) { |
||
| 108 | $redirectUri = $e->getAuthorization()->getRedirectUri(); |
||
| 109 | $responseMode = $e->getAuthorization()->getResponseMode(); |
||
| 110 | if (null !== $redirectUri && null !== $responseMode) { |
||
| 111 | $data['redirect_uri'] = $redirectUri; |
||
| 112 | $data['response_mode'] = $responseMode; |
||
| 113 | |||
| 114 | throw new OAuth2AuthorizationException(302, $data, $e->getAuthorization(), $e); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | throw $e; |
||
| 119 | } catch (Exception\ProcessAuthorizationException $e) { |
||
| 120 | $authorization = $e->getAuthorization(); |
||
| 121 | $authorization = $this->consentScreenExtensionManager->processAfter($request, $authorization); |
||
| 122 | if (false === $authorization->isAuthorized()) { |
||
| 123 | $this->throwRedirectionException($authorization, OAuth2Exception::ERROR_ACCESS_DENIED, 'The resource owner denied access to your client.'); |
||
| 124 | } |
||
| 125 | |||
| 126 | $responseType = $authorization->getResponseType(); |
||
| 127 | |||
| 128 | try { |
||
| 129 | $authorization = $responseType->process($authorization); |
||
| 130 | } catch (OAuth2Exception $e) { |
||
| 131 | $this->throwRedirectionException($authorization, $e->getMessage(), $e->getErrorDescription()); |
||
| 132 | } |
||
| 133 | |||
| 134 | return $this->buildResponse($authorization); |
||
| 135 | } catch (Exception\CreateRedirectionException $e) { |
||
| 136 | $this->throwRedirectionException($e->getAuthorization(), $e->getMessage(), $e->getDescription()); |
||
| 137 | } catch (Exception\ShowConsentScreenException $e) { |
||
| 138 | return $this->processConsentScreen($request, $e->getAuthorization()); |
||
| 139 | } catch (Exception\RedirectToLoginPageException $e) { |
||
| 140 | return $this->redirectToLoginPage($request, $e->getAuthorization()); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 206 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: