Complex classes like JoseCollector 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 JoseCollector, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 39 | final class JoseCollector extends DataCollector |
||
| 40 | { |
||
| 41 | /** |
||
| 42 | * @var AlgorithmManagerFactory |
||
| 43 | */ |
||
| 44 | private $algorithmManagerFactory; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var CompressionMethodManagerFactory|null |
||
| 48 | */ |
||
| 49 | private $compressionMethodManagerFactory; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var JWSSerializerManagerFactory|null |
||
| 53 | */ |
||
| 54 | private $jwsSerializerManagerFactory; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var JWESerializerManagerFactory|null |
||
| 58 | */ |
||
| 59 | private $jweSerializerManagerFactory; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var KeyAnalyzerManager|null |
||
| 63 | */ |
||
| 64 | private $jwkAnalyzerManager; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var ClaimCheckerManagerFactory|null |
||
| 68 | */ |
||
| 69 | private $claimCheckerManagerFactory; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var HeaderCheckerManagerFactory|null |
||
| 73 | */ |
||
| 74 | private $headerCheckerManagerFactory; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * JoseCollector constructor. |
||
| 78 | * |
||
| 79 | * @param AlgorithmManagerFactory $algorithmManagerFactory |
||
| 80 | * @param CompressionMethodManagerFactory|null $compressionMethodManagerFactory |
||
| 81 | * @param JWSSerializerManagerFactory|null $jwsSerializerManagerFactory |
||
| 82 | * @param JWESerializerManagerFactory|null $jweSerializerManagerFactory |
||
| 83 | * @param KeyAnalyzerManager|null $jwkAnalyzerManager |
||
| 84 | * @param ClaimCheckerManagerFactory|null $claimCheckerManagerFactory |
||
| 85 | * @param HeaderCheckerManagerFactory|null $headerCheckerManagerFactory |
||
| 86 | */ |
||
| 87 | public function __construct( |
||
| 105 | |||
| 106 | /** |
||
| 107 | * {@inheritdoc} |
||
| 108 | */ |
||
| 109 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return array |
||
| 127 | */ |
||
| 128 | public function getAlgorithmDetails(): array |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return int |
||
| 135 | */ |
||
| 136 | public function countSignatureAlgorithms(): int |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return int |
||
| 143 | */ |
||
| 144 | public function countKeyEncryptionAlgorithms(): int |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @return int |
||
| 151 | */ |
||
| 152 | public function countContentEncryptionAlgorithms(): int |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return array |
||
| 159 | */ |
||
| 160 | public function getCompressionMethodDetails(): array |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return array |
||
| 167 | */ |
||
| 168 | public function getJWSSerializationDetails(): array |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return array |
||
| 175 | */ |
||
| 176 | public function getJWESerializationDetails(): array |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @return array |
||
| 183 | */ |
||
| 184 | public function getJWKs(): array |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @return array |
||
| 191 | */ |
||
| 192 | public function getJWKSets(): array |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return array |
||
| 199 | */ |
||
| 200 | public function getJWSBuilders(): array |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @return array |
||
| 207 | */ |
||
| 208 | public function getJWSVerifiers(): array |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return array |
||
| 215 | */ |
||
| 216 | public function getJWEBuilders(): array |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return array |
||
| 223 | */ |
||
| 224 | public function getJWEDecrypters(): array |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return array |
||
| 231 | */ |
||
| 232 | public function getHeaderCheckers(): array |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @return array |
||
| 239 | */ |
||
| 240 | public function getHeaderCheckerManagers(): array |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return array |
||
| 247 | */ |
||
| 248 | public function getClaimCheckers(): array |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @return array |
||
| 255 | */ |
||
| 256 | public function getClaimCheckerManagers(): array |
||
| 260 | |||
| 261 | /** |
||
| 262 | * {@inheritdoc} |
||
| 263 | */ |
||
| 264 | public function getName() |
||
| 268 | |||
| 269 | private function collectSupportedHeaderCheckers() |
||
| 282 | |||
| 283 | private function collectSupportedClaimCheckers() |
||
| 295 | |||
| 296 | private function collectSupportedAlgorithms() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @param Algorithm $algorithm |
||
| 322 | * @param int $signatureAlgorithms |
||
| 323 | * @param int $keyEncryptionAlgorithms |
||
| 324 | * @param int $contentEncryptionAlgorithms |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | private function getAlgorithmType(Algorithm $algorithm, int &$signatureAlgorithms, int &$keyEncryptionAlgorithms, int &$contentEncryptionAlgorithms): string |
||
| 347 | |||
| 348 | private function collectSupportedCompressionMethods() |
||
| 359 | |||
| 360 | private function collectSupportedJWSSerializations() |
||
| 371 | |||
| 372 | private function collectSupportedJWESerializations() |
||
| 383 | |||
| 384 | private function collectSupportedJWSBuilders() |
||
| 393 | |||
| 394 | private function collectSupportedJWSVerifiers() |
||
| 403 | |||
| 404 | private function collectSupportedJWEBuilders() |
||
| 415 | |||
| 416 | private function collectSupportedJWEDecrypters() |
||
| 427 | |||
| 428 | private function collectJWK() |
||
| 438 | |||
| 439 | private function collectJWKSet() |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @var HeaderCheckerManager[] |
||
| 458 | */ |
||
| 459 | private $headerCheckerManagers = []; |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @param string $id |
||
| 463 | * @param HeaderCheckerManager $headerCheckerManager |
||
| 464 | */ |
||
| 465 | public function addHeaderCheckerManager(string $id, HeaderCheckerManager $headerCheckerManager) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * @var ClaimCheckerManager[] |
||
| 472 | */ |
||
| 473 | private $claimCheckerManagers = []; |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @param string $id |
||
| 477 | * @param ClaimCheckerManager $claimCheckerManager |
||
| 478 | */ |
||
| 479 | public function addClaimCheckerManager(string $id, ClaimCheckerManager $claimCheckerManager) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @var JWSBuilder[] |
||
| 486 | */ |
||
| 487 | private $jwsBuilders = []; |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @param string $id |
||
| 491 | * @param JWSBuilder $jwsBuilder |
||
| 492 | */ |
||
| 493 | public function addJWSBuilder(string $id, JWSBuilder $jwsBuilder) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @var JWSVerifier[] |
||
| 500 | */ |
||
| 501 | private $jwsVerifiers = []; |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @param string $id |
||
| 505 | * @param JWSVerifier $jwsVerifier |
||
| 506 | */ |
||
| 507 | public function addJWSVerifier(string $id, JWSVerifier $jwsVerifier) |
||
| 511 | |||
| 512 | /** |
||
| 513 | * @var JWEBuilder[] |
||
| 514 | */ |
||
| 515 | private $jweBuilders = []; |
||
| 516 | |||
| 517 | /** |
||
| 518 | * @param string $id |
||
| 519 | * @param JWEBuilder $jweBuilder |
||
| 520 | */ |
||
| 521 | public function addJWEBuilder(string $id, JWEBuilder $jweBuilder) |
||
| 525 | |||
| 526 | /** |
||
| 527 | * @var JWEDecrypter[] |
||
| 528 | */ |
||
| 529 | private $jweDecrypters = []; |
||
| 530 | |||
| 531 | /** |
||
| 532 | * @param string $id |
||
| 533 | * @param JWEDecrypter $jweDecrypter |
||
| 534 | */ |
||
| 535 | public function addJWEDecrypter(string $id, JWEDecrypter $jweDecrypter) |
||
| 539 | |||
| 540 | /** |
||
| 541 | * @var JWK[] |
||
| 542 | */ |
||
| 543 | private $jwks = []; |
||
| 544 | |||
| 545 | /** |
||
| 546 | * @param string $id |
||
| 547 | * @param JWK $jwk |
||
| 548 | */ |
||
| 549 | public function addJWK(string $id, JWK $jwk) |
||
| 553 | |||
| 554 | /** |
||
| 555 | * @var JWKSet[] |
||
| 556 | */ |
||
| 557 | private $jwksets = []; |
||
| 558 | |||
| 559 | /** |
||
| 560 | * @param string $id |
||
| 561 | * @param JWKSet $jwkset |
||
| 562 | */ |
||
| 563 | public function addJWKSet(string $id, JWKSet $jwkset) |
||
| 567 | } |
||
| 568 |
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: