Conditions | 7 |
Paths | 46 |
Total Lines | 71 |
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 |
||
57 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
58 | { |
||
59 | try { |
||
60 | // Loads the request and check the parameters |
||
61 | $authorization = $this->authorizationRequestLoader->load($request); |
||
62 | $authorization = $this->parameterCheckerManager->process($authorization); |
||
63 | |||
64 | //Retrieve the end user account |
||
65 | $userAccount = $this->userAccountDiscovery->find(); |
||
66 | if (null !== $userAccount) { |
||
67 | // Process with authenticated user |
||
68 | $isFullyAuthenticated = $this->userAccountDiscovery->isFullyAuthenticated(); |
||
69 | $authorization->setUserAccount($userAccount, $isFullyAuthenticated); |
||
70 | |||
71 | //Check the user against the available rules e.g.: |
||
72 | // * prompt login => redirect to login page |
||
73 | // * max_age/default_max_age => redirect to login page |
||
74 | if (!$isFullyAuthenticated) { |
||
75 | $this->userAccountCheckerManager->check($authorization); |
||
76 | } |
||
77 | |||
78 | if ($authorization->hasPrompt('none')) { |
||
79 | //TODO: No interaction. Should verified if the authorization has previously been given |
||
80 | $this->throwOAuth2Error($authorization, OAuth2Error::ERROR_INTERACTION_REQUIRED, 'The resource owner consent is required.'); |
||
81 | } else { |
||
82 | //Ask for consent |
||
83 | $authorization = $this->extensionManager->processBefore($request, $authorization); |
||
84 | } |
||
85 | |||
86 | return $this->processConsentScreen($request, $authorization); |
||
87 | } else { |
||
88 | // Process with unauthenticated user |
||
89 | |||
90 | // If prompt = none => no interaction |
||
91 | if ($authorization->hasPrompt('none')) { |
||
92 | //throw error login required |
||
93 | $this->throwOAuth2Error($authorization, OAuth2Error::ERROR_LOGIN_REQUIRED, 'The resource owner is not logged in.'); |
||
94 | } |
||
95 | |||
96 | // Else => user authentication required |
||
97 | return $this->redirectToLoginPage($request, $authorization); |
||
98 | } |
||
99 | } catch (OAuth2Error $e) { |
||
100 | throw $e; |
||
101 | } catch (\Exception $e) { |
||
102 | throw $e; |
||
103 | }/* catch (Exception\ProcessAuthorizationException $e) { |
||
|
|||
104 | $authorization = $e->getAuthorization(); |
||
105 | $authorization = $this->extensionManager->processAfter($request, $authorization); |
||
106 | if (false === $authorization->isAuthorized()) { |
||
107 | $this->throwOAuth2Error($authorization, OAuth2Message::ERROR_ACCESS_DENIED, 'The resource owner denied access to your client.'); |
||
108 | } |
||
109 | |||
110 | $responseType = $authorization->getResponseType(); |
||
111 | |||
112 | try { |
||
113 | $authorization = $responseType->preProcess($authorization); |
||
114 | $authorization = $responseType->process($authorization); |
||
115 | } catch (OAuth2Message $e) { |
||
116 | $this->throwOAuth2Error($authorization, $e->getMessage(), $e->getErrorDescription()); |
||
117 | } |
||
118 | |||
119 | return $this->buildResponse($authorization); |
||
120 | } catch (Exception\CreateRedirectionException $e) { |
||
121 | $this->throwOAuth2Error($e->getAuthorization(), $e->getMessage(), $e->getDescription()); |
||
122 | } catch (Exception\ShowConsentScreenException $e) { |
||
123 | return $this->processConsentScreen($request, $e->getAuthorization()); |
||
124 | } catch (Exception\RedirectToLoginPageException $e) { |
||
125 | return $this->redirectToLoginPage($request, $e->getAuthorization()); |
||
126 | }*/ |
||
127 | } |
||
128 | |||
157 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.