Conditions | 9 |
Paths | 6 |
Total Lines | 58 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 1 |
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 |
||
107 | public function validateAuthorizationRequest(ServerRequestInterface $request) |
||
108 | { |
||
109 | $clientId = $this->getQueryStringParameter( |
||
110 | 'client_id', |
||
111 | $request, |
||
112 | $this->getServerParameter('PHP_AUTH_USER', $request) |
||
113 | ); |
||
114 | if (is_null($clientId)) { |
||
115 | throw OAuthServerException::invalidRequest('client_id'); |
||
116 | } |
||
117 | |||
118 | $client = $this->clientRepository->getClientEntity( |
||
119 | $clientId, |
||
120 | $this->getIdentifier(), |
||
121 | null, |
||
122 | false |
||
123 | ); |
||
124 | |||
125 | if ($client instanceof ClientEntityInterface === false) { |
||
126 | $this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); |
||
127 | throw OAuthServerException::invalidClient(); |
||
128 | } |
||
129 | |||
130 | $redirectUri = $this->getQueryStringParameter('redirect_uri', $request); |
||
131 | if ($redirectUri !== null) { |
||
132 | if ( |
||
133 | is_string($client->getRedirectUri()) |
||
134 | && (strcmp($client->getRedirectUri(), $redirectUri) !== 0) |
||
135 | ) { |
||
136 | $this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); |
||
137 | throw OAuthServerException::invalidClient(); |
||
138 | } elseif ( |
||
139 | is_array($client->getRedirectUri()) |
||
140 | && in_array($redirectUri, $client->getRedirectUri()) === false |
||
141 | ) { |
||
142 | $this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); |
||
143 | throw OAuthServerException::invalidClient(); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | $scopes = $this->validateScopes( |
||
148 | $this->getQueryStringParameter('scope', $request), |
||
149 | is_array($client->getRedirectUri()) |
||
150 | ? $client->getRedirectUri()[0] |
||
151 | : $client->getRedirectUri() |
||
152 | ); |
||
153 | |||
154 | $stateParameter = $this->getQueryStringParameter('state', $request); |
||
155 | |||
156 | $authorizationRequest = new AuthorizationRequest(); |
||
157 | $authorizationRequest->setGrantTypeId($this->getIdentifier()); |
||
158 | $authorizationRequest->setClient($client); |
||
159 | $authorizationRequest->setRedirectUri($redirectUri); |
||
160 | $authorizationRequest->setState($stateParameter); |
||
161 | $authorizationRequest->setScopes($scopes); |
||
162 | |||
163 | return $authorizationRequest; |
||
164 | } |
||
165 | |||
214 |