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 |
||
34 | class AuthorizationRequestLoader |
||
35 | { |
||
36 | /** |
||
37 | * @var ClientRepository |
||
38 | */ |
||
39 | private $clientRepository; |
||
40 | |||
41 | /** |
||
42 | * @var bool |
||
43 | */ |
||
44 | private $requestObjectAllowed = false; |
||
45 | |||
46 | /** |
||
47 | * @var bool |
||
48 | */ |
||
49 | private $requestObjectReferenceAllowed = false; |
||
50 | |||
51 | /** |
||
52 | * @var JWKSet |
||
53 | */ |
||
54 | private $keyEncryptionKeySet = null; |
||
55 | |||
56 | /** |
||
57 | * @var bool |
||
58 | */ |
||
59 | private $requireRequestUriRegistration = true; |
||
60 | |||
61 | /** |
||
62 | * @var bool |
||
63 | */ |
||
64 | private $requireEncryption = false; |
||
65 | |||
66 | /** |
||
67 | * @var null|HttpClient |
||
68 | */ |
||
69 | private $client = null; |
||
70 | |||
71 | /** |
||
72 | * @var JWSVerifier |
||
73 | */ |
||
74 | private $jwsVerifier = null; |
||
75 | |||
76 | /** |
||
77 | * @var ClaimCheckerManager |
||
78 | */ |
||
79 | private $claimCheckerManager = null; |
||
80 | |||
81 | /** |
||
82 | * @var JWELoader |
||
83 | */ |
||
84 | private $jweLoader = null; |
||
85 | |||
86 | /** |
||
87 | * @var null|JKUFactory |
||
88 | */ |
||
89 | private $jkuFactory = null; |
||
90 | |||
91 | /** |
||
92 | * AuthorizationRequestLoader constructor. |
||
93 | * |
||
94 | * @param ClientRepository $clientRepository |
||
95 | */ |
||
96 | public function __construct(ClientRepository $clientRepository) |
||
100 | |||
101 | /** |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function isRequestUriRegistrationRequired(): bool |
||
108 | |||
109 | /** |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function isRequestObjectSupportEnabled(): bool |
||
116 | |||
117 | /** |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function isRequestObjectReferenceSupportEnabled(): bool |
||
124 | |||
125 | /** |
||
126 | * @return string[] |
||
127 | */ |
||
128 | public function getSupportedSignatureAlgorithms(): array |
||
132 | |||
133 | /** |
||
134 | * @return string[] |
||
135 | */ |
||
136 | public function getSupportedKeyEncryptionAlgorithms(): array |
||
140 | |||
141 | /** |
||
142 | * @return string[] |
||
143 | */ |
||
144 | public function getSupportedContentEncryptionAlgorithms(): array |
||
148 | |||
149 | /** |
||
150 | * @param JWSVerifier $jwsVerifier |
||
151 | * @param ClaimCheckerManager $claimCheckerManager |
||
152 | */ |
||
153 | public function enableSignedRequestObjectSupport(JWSVerifier $jwsVerifier, ClaimCheckerManager $claimCheckerManager) |
||
159 | |||
160 | /** |
||
161 | * @param HttpClient $client |
||
162 | * @param bool $requireRequestUriRegistration |
||
163 | */ |
||
164 | public function enableRequestObjectReferenceSupport(HttpClient $client, bool $requireRequestUriRegistration) |
||
173 | |||
174 | /** |
||
175 | * @param JWELoader $jweLoader |
||
176 | * @param JWKSet $keyEncryptionKeySet |
||
177 | * @param bool $requireEncryption |
||
178 | * |
||
179 | * @throws \InvalidArgumentException |
||
180 | */ |
||
181 | public function enableEncryptedRequestObjectSupport(JWELoader $jweLoader, JWKSet $keyEncryptionKeySet, bool $requireEncryption) |
||
193 | |||
194 | /** |
||
195 | * @param JKUFactory $jkuFactory |
||
196 | */ |
||
197 | public function enableJkuSupport(JKUFactory $jkuFactory) |
||
201 | |||
202 | /** |
||
203 | * @return bool |
||
204 | */ |
||
205 | public function isEncryptedRequestSupportEnabled(): bool |
||
209 | |||
210 | /** |
||
211 | * @param ServerRequestInterface $request |
||
212 | * |
||
213 | * @return Authorization |
||
214 | * |
||
215 | * @throws OAuth2Exception |
||
216 | * @throws \Exception |
||
217 | * @throws \Http\Client\Exception |
||
218 | */ |
||
219 | public function load(ServerRequestInterface $request): Authorization |
||
233 | |||
234 | /** |
||
235 | * @param array $params |
||
236 | * @param Client $client |
||
237 | * |
||
238 | * @throws OAuth2Exception |
||
239 | * |
||
240 | * @return array |
||
241 | */ |
||
242 | private function createFromRequestParameter(array $params, Client &$client = null): array |
||
257 | |||
258 | /** |
||
259 | * @param array $params |
||
260 | * @param Client $client |
||
261 | * |
||
262 | * @return array |
||
263 | * |
||
264 | * @throws OAuth2Exception |
||
265 | * @throws \Exception |
||
266 | * @throws \Http\Client\Exception |
||
267 | */ |
||
268 | private function createFromRequestUriParameter(array $params, Client &$client = null): array |
||
284 | |||
285 | /** |
||
286 | * @param array $params |
||
287 | * |
||
288 | * @throws \InvalidArgumentException |
||
289 | */ |
||
290 | private function checkIssuerAndClientId(array $params) |
||
298 | |||
299 | /** |
||
300 | * @param Client $client |
||
301 | * @param string $requestUri |
||
302 | * |
||
303 | * @throws OAuth2Exception |
||
304 | */ |
||
305 | private function checkRequestUri(Client $client, $requestUri) |
||
323 | |||
324 | /** |
||
325 | * @param array $params |
||
326 | * @param string $request |
||
327 | * @param Client|null $client |
||
328 | * |
||
329 | * @throws OAuth2Exception |
||
330 | * |
||
331 | * @return array |
||
332 | */ |
||
333 | private function loadRequestObject(array $params, string $request, Client &$client = null): array |
||
369 | |||
370 | /** |
||
371 | * @param string $request |
||
372 | * |
||
373 | * @return string |
||
374 | * |
||
375 | * @throws OAuth2Exception |
||
376 | */ |
||
377 | private function tryToLoadEncryptedRequest(string $request): string |
||
398 | |||
399 | /** |
||
400 | * @param JWS $jws |
||
401 | * @param Client $client |
||
402 | * |
||
403 | * @throws \InvalidArgumentException |
||
404 | */ |
||
405 | private function checkAlgorithms(JWS $jws, Client $client) |
||
413 | |||
414 | /** |
||
415 | * @param string $algorithm |
||
416 | */ |
||
417 | private function checkUsedAlgorithm(string $algorithm) |
||
424 | |||
425 | /** |
||
426 | * @param $url |
||
427 | * |
||
428 | * @return string |
||
429 | * |
||
430 | * @throws OAuth2Exception |
||
431 | * @throws \Exception |
||
432 | * @throws \Http\Client\Exception |
||
433 | */ |
||
434 | private function downloadContent($url): string |
||
449 | |||
450 | /** |
||
451 | * @param array $params |
||
452 | * |
||
453 | * @throws OAuth2Exception |
||
454 | * |
||
455 | * @return Client |
||
456 | */ |
||
457 | private function getClient(array $params): Client |
||
466 | |||
467 | /** |
||
468 | * @param Client $client |
||
469 | * |
||
470 | * @return JWKSet |
||
471 | */ |
||
472 | private function getClientKeySet(Client $client): JWKSet |
||
491 | } |
||
492 |
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: