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 | final 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 |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @param string $request |
||
| 393 | * |
||
| 394 | * @return string |
||
| 395 | * |
||
| 396 | * @throws OAuth2Exception |
||
| 397 | */ |
||
| 398 | private function tryToLoadEncryptedRequest(string $request): string |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @param JWS $jws |
||
| 422 | * @param int $index |
||
| 423 | * @param Client $client |
||
| 424 | * |
||
| 425 | * @throws \InvalidArgumentException |
||
| 426 | */ |
||
| 427 | private function checkAlgorithms(JWS $jws, int $index, Client $client) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @param $url |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | * |
||
| 442 | * @throws OAuth2Exception |
||
| 443 | * @throws \Exception |
||
| 444 | * @throws \Http\Client\Exception |
||
| 445 | */ |
||
| 446 | private function downloadContent($url): string |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @param array $params |
||
| 464 | * |
||
| 465 | * @throws OAuth2Exception |
||
| 466 | * |
||
| 467 | * @return Client |
||
| 468 | */ |
||
| 469 | private function getClient(array $params): Client |
||
| 478 | } |
||
| 479 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.