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 |
||
29 | class AuthorizationRequestLoader |
||
30 | { |
||
31 | /** |
||
32 | * @var ClientRepository |
||
33 | */ |
||
34 | private $clientRepository; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $requestObjectAllowed = false; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | private $requestObjectReferenceAllowed = false; |
||
45 | |||
46 | /** |
||
47 | * @var JWKSet |
||
48 | */ |
||
49 | private $keyEncryptionKeySet = null; |
||
50 | |||
51 | /** |
||
52 | * @var bool |
||
53 | */ |
||
54 | private $requireRequestUriRegistration = true; |
||
55 | |||
56 | /** |
||
57 | * @var bool |
||
58 | */ |
||
59 | private $requireEncryption = false; |
||
60 | |||
61 | /** |
||
62 | * @var string[] |
||
63 | */ |
||
64 | private $mandatoryClaims = []; |
||
65 | |||
66 | /** |
||
67 | * @var null|HttpClient |
||
68 | */ |
||
69 | private $client = null; |
||
70 | |||
71 | /** |
||
72 | * @var JWSLoader |
||
73 | */ |
||
74 | private $jwsLoader = null; |
||
75 | |||
76 | /** |
||
77 | * @var ClaimCheckerManager |
||
78 | */ |
||
79 | private $claimCheckerManager = null; |
||
80 | |||
81 | /** |
||
82 | * @var JWELoader |
||
83 | */ |
||
84 | private $jweLoader = null; |
||
85 | |||
86 | /** |
||
87 | * AuthorizationRequestLoader constructor. |
||
88 | * |
||
89 | * @param ClientRepository $clientRepository |
||
90 | */ |
||
91 | public function __construct(ClientRepository $clientRepository) |
||
95 | |||
96 | /** |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function isRequestUriRegistrationRequired(): bool |
||
103 | |||
104 | /** |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function isRequestObjectSupportEnabled(): bool |
||
111 | |||
112 | /** |
||
113 | * @return bool |
||
114 | */ |
||
115 | public function isRequestObjectReferenceSupportEnabled(): bool |
||
119 | |||
120 | /** |
||
121 | * @return string[] |
||
122 | */ |
||
123 | public function getSupportedSignatureAlgorithms(): array |
||
127 | |||
128 | /** |
||
129 | * @return string[] |
||
130 | */ |
||
131 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
135 | |||
136 | /** |
||
137 | * @return string[] |
||
138 | */ |
||
139 | public function getSupportedContentEncryptionAlgorithms(): array |
||
143 | |||
144 | /** |
||
145 | * @param JWSLoader $jwsLoader |
||
146 | * @param ClaimCheckerManager $claimCheckerManager |
||
147 | * @param string[] $mandatoryClaims |
||
148 | */ |
||
149 | public function enableRequestObjectSupport(JWSLoader $jwsLoader, ClaimCheckerManager $claimCheckerManager, array $mandatoryClaims = []) |
||
161 | |||
162 | /** |
||
163 | * @param HttpClient $client |
||
164 | * @param bool $requireRequestUriRegistration |
||
165 | */ |
||
166 | public function enableRequestObjectReferenceSupport(HttpClient $client, bool $requireRequestUriRegistration) |
||
175 | |||
176 | /** |
||
177 | * @param JWELoader $jweLoader |
||
178 | * @param JWKSet $keyEncryptionKeySet |
||
179 | * @param bool $requireEncryption |
||
180 | * |
||
181 | * @throws \InvalidArgumentException |
||
182 | */ |
||
183 | public function enableEncryptedRequestObjectSupport(JWELoader $jweLoader, JWKSet $keyEncryptionKeySet, bool $requireEncryption) |
||
195 | |||
196 | /** |
||
197 | * @return bool |
||
198 | */ |
||
199 | public function isEncryptedRequestsSupportEnabled(): bool |
||
203 | |||
204 | /** |
||
205 | * @param ServerRequestInterface $request |
||
206 | * |
||
207 | * @return array |
||
208 | * |
||
209 | * @throws OAuth2Exception |
||
210 | * @throws \Exception |
||
211 | * @throws \Http\Client\Exception |
||
212 | */ |
||
213 | public function loadParametersFromRequest(ServerRequestInterface $request): array |
||
229 | |||
230 | /** |
||
231 | * @param array $params |
||
232 | * |
||
233 | * @throws OAuth2Exception |
||
234 | * |
||
235 | * @return array |
||
236 | */ |
||
237 | private function createFromRequestParameter(array $params): array |
||
254 | |||
255 | /** |
||
256 | * @param array $params |
||
257 | * |
||
258 | * @return array |
||
259 | * |
||
260 | * @throws OAuth2Exception |
||
261 | */ |
||
262 | private function createFromStandardRequest(array $params): array |
||
268 | |||
269 | /** |
||
270 | * @param array $params |
||
271 | * |
||
272 | * @return array |
||
273 | * |
||
274 | * @throws OAuth2Exception |
||
275 | * @throws \Exception |
||
276 | * @throws \Http\Client\Exception |
||
277 | */ |
||
278 | private function createFromRequestUriParameter(array $params): array |
||
296 | |||
297 | /** |
||
298 | * @param array $params |
||
299 | * |
||
300 | * @throws \InvalidArgumentException |
||
301 | */ |
||
302 | private function checkIssuerAndClientId(array $params) |
||
310 | |||
311 | /** |
||
312 | * @param Client $client |
||
313 | * @param string $requestUri |
||
314 | * |
||
315 | * @throws OAuth2Exception |
||
316 | */ |
||
317 | private function checkRequestUri(Client $client, $requestUri) |
||
330 | |||
331 | /** |
||
332 | * @param string $requestUri |
||
333 | * |
||
334 | * @throws OAuth2Exception |
||
335 | */ |
||
336 | private function checkRequestUriPathTraversal($requestUri) |
||
342 | |||
343 | /** |
||
344 | * @param Client $client |
||
345 | * |
||
346 | * @throws OAuth2Exception |
||
347 | * |
||
348 | * @return string[] |
||
349 | */ |
||
350 | private function getClientRequestUris(Client $client): array |
||
358 | |||
359 | /** |
||
360 | * @param array $params |
||
361 | * @param string $request |
||
362 | * @param Client|null $client |
||
363 | * |
||
364 | * @throws OAuth2Exception |
||
365 | * |
||
366 | * @return JWS |
||
367 | */ |
||
368 | private function loadRequest(array $params, string $request, Client &$client = null): JWS |
||
394 | |||
395 | /** |
||
396 | * @param string $request |
||
397 | * |
||
398 | * @return string |
||
399 | * |
||
400 | * @throws OAuth2Exception |
||
401 | */ |
||
402 | private function tryToLoadEncryptedRequest(string $request): string |
||
423 | |||
424 | /** |
||
425 | * @param JWS $jws |
||
426 | * @param int $index |
||
427 | * @param Client $client |
||
428 | * |
||
429 | * @throws \InvalidArgumentException |
||
430 | */ |
||
431 | private function checkAlgorithms(JWS $jws, int $index, Client $client) |
||
440 | |||
441 | /** |
||
442 | * @param $url |
||
443 | * |
||
444 | * @return string |
||
445 | * |
||
446 | * @throws OAuth2Exception |
||
447 | * @throws \Exception |
||
448 | * @throws \Http\Client\Exception |
||
449 | */ |
||
450 | private function downloadContent($url): string |
||
465 | |||
466 | /** |
||
467 | * @param array $params |
||
468 | * |
||
469 | * @throws OAuth2Exception |
||
470 | * |
||
471 | * @return Client |
||
472 | */ |
||
473 | private function getClient(array $params): Client |
||
482 | } |
||
483 |
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: