Complex classes like AuthorizationRequestLoader often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AuthorizationRequestLoader, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | final class AuthorizationRequestLoader |
||
33 | { |
||
34 | /** |
||
35 | * @var ClientRepositoryInterface |
||
36 | */ |
||
37 | private $clientRepository; |
||
38 | |||
39 | /** |
||
40 | * @var bool |
||
41 | */ |
||
42 | private $requestObjectAllowed = false; |
||
43 | |||
44 | /** |
||
45 | * @var bool |
||
46 | */ |
||
47 | private $requestObjectReferenceAllowed = false; |
||
48 | |||
49 | /** |
||
50 | * @var JWKSet |
||
51 | */ |
||
52 | private $keyEncryptionKeySet = null; |
||
53 | |||
54 | /** |
||
55 | * @var bool |
||
56 | */ |
||
57 | private $requireRequestUriRegistration = true; |
||
58 | |||
59 | /** |
||
60 | * @var bool |
||
61 | */ |
||
62 | private $requireEncryption = false; |
||
63 | |||
64 | /** |
||
65 | * @var string[] |
||
66 | */ |
||
67 | private $mandatoryClaims = []; |
||
68 | |||
69 | /** |
||
70 | * @var null|HttpClient |
||
71 | */ |
||
72 | private $client = null; |
||
73 | |||
74 | /** |
||
75 | * @var JWSLoader |
||
76 | */ |
||
77 | private $jwsLoader = null; |
||
78 | |||
79 | /** |
||
80 | * @var ClaimCheckerManager |
||
81 | */ |
||
82 | private $claimCheckerManager = null; |
||
83 | |||
84 | /** |
||
85 | * @var JWELoader |
||
86 | */ |
||
87 | private $jweLoader = null; |
||
88 | |||
89 | /** |
||
90 | * AuthorizationRequestLoader constructor. |
||
91 | * |
||
92 | * @param ClientRepositoryInterface $clientRepository |
||
93 | */ |
||
94 | public function __construct(ClientRepositoryInterface $clientRepository) |
||
98 | |||
99 | /** |
||
100 | * @return bool |
||
101 | */ |
||
102 | public function isRequestUriRegistrationRequired(): bool |
||
106 | |||
107 | /** |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function isRequestObjectSupportEnabled(): bool |
||
114 | |||
115 | /** |
||
116 | * @return bool |
||
117 | */ |
||
118 | public function isRequestObjectReferenceSupportEnabled(): bool |
||
122 | |||
123 | /** |
||
124 | * @return string[] |
||
125 | */ |
||
126 | public function getSupportedSignatureAlgorithms(): array |
||
130 | |||
131 | /** |
||
132 | * @return string[] |
||
133 | */ |
||
134 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
138 | |||
139 | /** |
||
140 | * @return string[] |
||
141 | */ |
||
142 | public function getSupportedContentEncryptionAlgorithms(): array |
||
146 | |||
147 | /** |
||
148 | * @param JWSLoader $jwsLoader |
||
149 | * @param ClaimCheckerManager $claimCheckerManager |
||
150 | * @param string[] $mandatoryClaims |
||
151 | */ |
||
152 | public function enableRequestObjectSupport(JWSLoader $jwsLoader, ClaimCheckerManager $claimCheckerManager, array $mandatoryClaims = []) |
||
160 | |||
161 | /** |
||
162 | * @param HttpClient $client |
||
163 | * @param bool $requireRequestUriRegistration |
||
164 | */ |
||
165 | public function enableRequestObjectReferenceSupport(HttpClient $client, bool $requireRequestUriRegistration) |
||
172 | |||
173 | /** |
||
174 | * @param JWELoader $jweLoader |
||
175 | * @param JWKSet $keyEncryptionKeySet |
||
176 | * @param bool $requireEncryption |
||
177 | */ |
||
178 | public function enableEncryptedRequestObjectSupport(JWELoader $jweLoader, JWKSet $keyEncryptionKeySet, bool $requireEncryption) |
||
186 | |||
187 | /** |
||
188 | * @return bool |
||
189 | */ |
||
190 | public function isEncryptedRequestsSupportEnabled(): bool |
||
194 | |||
195 | /** |
||
196 | * @param ServerRequestInterface $request |
||
197 | * |
||
198 | * @return array |
||
199 | */ |
||
200 | public function loadParametersFromRequest(ServerRequestInterface $request): array |
||
216 | |||
217 | /** |
||
218 | * @param array $params |
||
219 | * |
||
220 | * @throws OAuth2Exception |
||
221 | * |
||
222 | * @return array |
||
223 | */ |
||
224 | private function createFromRequestParameter(array $params): array |
||
239 | |||
240 | /** |
||
241 | * @param array $params |
||
242 | * |
||
243 | * @return array |
||
244 | */ |
||
245 | private function createFromStandardRequest(array $params): array |
||
251 | |||
252 | /** |
||
253 | * @param array $params |
||
254 | * |
||
255 | * @throws OAuth2Exception |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | private function createFromRequestUriParameter(array $params): array |
||
277 | |||
278 | /** |
||
279 | * @param array $params |
||
280 | * |
||
281 | * @throws OAuth2Exception |
||
282 | */ |
||
283 | private function checkIssuerAndClientId(array $params) |
||
289 | |||
290 | /** |
||
291 | * @param Client $client |
||
292 | * @param string $requestUri |
||
293 | * |
||
294 | * @throws OAuth2Exception |
||
295 | */ |
||
296 | private function checkRequestUri(Client $client, $requestUri) |
||
309 | |||
310 | /** |
||
311 | * @param string $requestUri |
||
312 | * |
||
313 | * @throws OAuth2Exception |
||
314 | */ |
||
315 | private function checkRequestUriPathTraversal($requestUri) |
||
321 | |||
322 | /** |
||
323 | * @param Client $client |
||
324 | * |
||
325 | * @throws OAuth2Exception |
||
326 | * |
||
327 | * @return string[] |
||
328 | */ |
||
329 | private function getClientRequestUris(Client $client): array |
||
337 | |||
338 | /** |
||
339 | * @param array $params |
||
340 | * @param string $request |
||
341 | * @param Client|null $client |
||
342 | * |
||
343 | * @throws OAuth2Exception |
||
344 | * |
||
345 | * @return JWS |
||
346 | */ |
||
347 | private function loadRequest(array $params, string $request, Client &$client = null): JWS |
||
369 | |||
370 | /** |
||
371 | * @param string $request |
||
372 | * |
||
373 | * @return string |
||
374 | * |
||
375 | * @throws OAuth2Exception |
||
376 | */ |
||
377 | private function tryToLoadEncryptedRequest(string $request): string |
||
396 | |||
397 | /** |
||
398 | * @param JWS $jwt |
||
399 | * @param int $index |
||
400 | * @param Client $client |
||
401 | */ |
||
402 | private function checkAlgorithms(JWS $jwt, int $index, Client $client) |
||
407 | |||
408 | /** |
||
409 | * @param string $url |
||
410 | * |
||
411 | * @throws OAuth2Exception |
||
412 | * |
||
413 | * @return string |
||
414 | */ |
||
415 | private function downloadContent($url): string |
||
428 | |||
429 | /** |
||
430 | * @param array $params |
||
431 | * |
||
432 | * @throws OAuth2Exception |
||
433 | * |
||
434 | * @return Client |
||
435 | */ |
||
436 | private function getClient(array $params): Client |
||
445 | } |
||
446 |
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: