Conditions | 11 |
Paths | 97 |
Total Lines | 60 |
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 |
||
54 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
55 | { |
||
56 | try { |
||
57 | $authorization = $this->authorizationRequestLoader->load($request); |
||
58 | $authorization = $this->parameterCheckerManager->process($authorization); |
||
59 | $userAccount = $this->userAccountDiscovery->find(); |
||
60 | |||
61 | if (null !== $userAccount) { |
||
62 | $isFullyAuthenticated = $this->userAccountDiscovery->isFullyAuthenticated(); |
||
63 | $authorization->setUserAccount($userAccount, $isFullyAuthenticated); |
||
64 | $this->userAccountCheckerManager->check($authorization); |
||
65 | |||
66 | switch (true) { |
||
67 | case $authorization->hasPrompt('none'): |
||
68 | if (!$this->consentRepository->hasConsentBeenGiven($authorization)) { |
||
69 | throw $this->buildOAuth2Error($authorization, OAuth2Error::ERROR_INTERACTION_REQUIRED, 'The resource owner consent is required.'); |
||
70 | } |
||
71 | $authorization->allow(); |
||
72 | $routeName = 'authorization_process_endpoint'; |
||
73 | break; |
||
74 | case $authorization->hasPrompt('login'): |
||
75 | $routeName = 'authorization_login_endpoint'; |
||
76 | break; |
||
77 | case $authorization->hasPrompt('select_account'): |
||
78 | $routeName = 'authorization_select_account_endpoint'; |
||
79 | break; |
||
80 | case $authorization->hasPrompt('consent'): |
||
81 | default: |
||
82 | $routeName = 'authorization_consent_endpoint'; |
||
83 | break; |
||
84 | } |
||
85 | |||
86 | $authorizationId = Base64Url::encode(random_bytes(64)); |
||
87 | $authorizationId = $this->saveAuthorization($authorizationId, $authorization); |
||
|
|||
88 | $redirectTo = $this->router->generate($routeName, ['authorization_id' => $authorizationId]); |
||
89 | |||
90 | return $this->createRedirectResponse($redirectTo); |
||
91 | } else { |
||
92 | if ($authorization->hasPrompt('none')) { |
||
93 | if (!$this->consentRepository->hasConsentBeenGiven($authorization)) { |
||
94 | throw $this->buildOAuth2Error($authorization, OAuth2Error::ERROR_LOGIN_REQUIRED, 'The resource owner is not logged in.'); |
||
95 | } |
||
96 | $authorization->allow(); |
||
97 | $routeName = 'authorization_process_endpoint'; |
||
98 | } else { |
||
99 | $routeName = 'authorization_login_endpoint'; |
||
100 | } |
||
101 | |||
102 | $authorizationId = Base64Url::encode(random_bytes(64)); |
||
103 | $authorizationId = $this->saveAuthorization($authorizationId, $authorization); |
||
104 | $redirectTo = $this->router->generate($routeName, ['authorization_id' => $authorizationId]); |
||
105 | |||
106 | return $this->createRedirectResponse($redirectTo); |
||
107 | } |
||
108 | } catch (OAuth2Error $e) { |
||
109 | throw $e; |
||
110 | } catch (\Exception $e) { |
||
111 | throw new OAuth2Error(400, OAuth2Error::ERROR_INVALID_REQUEST, null); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.