Complex classes like Factory 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 Factory, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class Factory |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Creates a new RData object from a name. |
||
| 22 | * |
||
| 23 | * @param string $name |
||
| 24 | * |
||
| 25 | * @throws UnsupportedTypeException |
||
| 26 | * |
||
| 27 | * @return RdataInterface |
||
| 28 | */ |
||
| 29 | 1 | public static function newRdataFromName(string $name): RdataInterface |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @param int $id |
||
| 42 | * |
||
| 43 | * @return RdataInterface |
||
| 44 | * |
||
| 45 | * @throws UnsupportedTypeException |
||
| 46 | */ |
||
| 47 | public static function newRdataFromId(int $id): RdataInterface |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @param string $name |
||
| 54 | * |
||
| 55 | * @return bool |
||
| 56 | */ |
||
| 57 | 17 | public static function isTypeImplemented(string $name): bool |
|
| 61 | |||
| 62 | /** |
||
| 63 | * @param string $type |
||
| 64 | * @param string $text |
||
| 65 | * |
||
| 66 | * @return RdataInterface |
||
| 67 | */ |
||
| 68 | 16 | public static function textToRdataType(string $type, string $text): RdataInterface |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Get the fully qualified class name of the RData class for $type. |
||
| 82 | * |
||
| 83 | * @param string $type |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | 17 | public static function getRdataClassName(string $type): string |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Create a new AAAA R-Data object. |
||
| 94 | * |
||
| 95 | * @param string $address |
||
| 96 | * |
||
| 97 | * @return AAAA |
||
| 98 | */ |
||
| 99 | 12 | public static function AAAA(string $address): AAAA |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Create a new A R-Data object. |
||
| 109 | * |
||
| 110 | * @param string $address |
||
| 111 | * |
||
| 112 | * @return A |
||
| 113 | */ |
||
| 114 | 12 | public static function A(string $address): A |
|
| 121 | |||
| 122 | /** |
||
| 123 | * Create a new CNAME object. |
||
| 124 | * |
||
| 125 | * @param string $cname |
||
| 126 | * |
||
| 127 | * @return CNAME |
||
| 128 | */ |
||
| 129 | 9 | public static function CNAME(string $cname): CNAME |
|
| 136 | |||
| 137 | /** |
||
| 138 | * @param string $cpu |
||
| 139 | * @param string $os |
||
| 140 | * |
||
| 141 | * @return HINFO |
||
| 142 | */ |
||
| 143 | 9 | public static function HINFO(string $cpu, string $os): HINFO |
|
| 151 | |||
| 152 | /** |
||
| 153 | * @param int $preference |
||
| 154 | * @param string $exchange |
||
| 155 | * |
||
| 156 | * @return MX |
||
| 157 | */ |
||
| 158 | 11 | public static function MX(int $preference, string $exchange): MX |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @param string $mname |
||
| 169 | * @param string $rname |
||
| 170 | * @param int $serial |
||
| 171 | * @param int $refresh |
||
| 172 | * @param int $retry |
||
| 173 | * @param int $expire |
||
| 174 | * @param int $minimum |
||
| 175 | * |
||
| 176 | * @return SOA |
||
| 177 | */ |
||
| 178 | 14 | public static function SOA(string $mname, string $rname, int $serial, int $refresh, int $retry, int $expire, int $minimum): SOA |
|
| 191 | |||
| 192 | /** |
||
| 193 | * @param string $nsdname |
||
| 194 | * |
||
| 195 | * @return NS |
||
| 196 | */ |
||
| 197 | 13 | public static function NS(string $nsdname): NS |
|
| 204 | |||
| 205 | /** |
||
| 206 | * @param string $text |
||
| 207 | * |
||
| 208 | * @return TXT |
||
| 209 | */ |
||
| 210 | 10 | public static function TXT(string $text): TXT |
|
| 217 | |||
| 218 | /** |
||
| 219 | * @param string $target |
||
| 220 | * |
||
| 221 | * @return DNAME |
||
| 222 | */ |
||
| 223 | 9 | public static function DNAME(string $target): DNAME |
|
| 230 | |||
| 231 | /** |
||
| 232 | * @param float $lat |
||
| 233 | * @param float $lon |
||
| 234 | * @param float $alt |
||
| 235 | * @param float $size |
||
| 236 | * @param float $hp |
||
| 237 | * @param float $vp |
||
| 238 | * |
||
| 239 | * @return LOC |
||
| 240 | */ |
||
| 241 | 10 | public static function LOC(float $lat, float $lon, $alt = 0.0, $size = 1.0, $hp = 10000.0, $vp = 10.0): LOC |
|
| 253 | |||
| 254 | /** |
||
| 255 | * @param string $target |
||
| 256 | * |
||
| 257 | * @return PTR |
||
| 258 | */ |
||
| 259 | 2 | public static function PTR(string $target): PTR |
|
| 266 | |||
| 267 | /** |
||
| 268 | * @param int $flags |
||
| 269 | * @param int $algorithm |
||
| 270 | * @param string $publicKey |
||
| 271 | * |
||
| 272 | * @return DNSKEY |
||
| 273 | */ |
||
| 274 | 1 | public static function DNSKEY(int $flags, int $algorithm, string $publicKey): DNSKEY |
|
| 283 | |||
| 284 | /** |
||
| 285 | * @param int $keyTag |
||
| 286 | * @param int $algorithm |
||
| 287 | * @param string $digest |
||
| 288 | * @param int $digestType |
||
| 289 | * |
||
| 290 | * @return DS |
||
| 291 | */ |
||
| 292 | 1 | public static function DS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DS |
|
| 302 | |||
| 303 | /** |
||
| 304 | * @param string $nextDomainName |
||
| 305 | * @param array $types |
||
| 306 | * |
||
| 307 | * @return NSEC |
||
| 308 | */ |
||
| 309 | 1 | public static function NSEC(string $nextDomainName, array $types): NSEC |
|
| 317 | |||
| 318 | /** |
||
| 319 | * @param string $typeCovered |
||
| 320 | * @param int $algorithm |
||
| 321 | * @param int $labels |
||
| 322 | * @param int $originalTtl |
||
| 323 | * @param \DateTime $signatureExpiration |
||
| 324 | * @param \DateTime $signatureInception |
||
| 325 | * @param int $keyTag |
||
| 326 | * @param string $signersName |
||
| 327 | * @param string $signature |
||
| 328 | * |
||
| 329 | * @return RRSIG |
||
| 330 | */ |
||
| 331 | 1 | public static function RRSIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl, |
|
| 348 | |||
| 349 | /** |
||
| 350 | * @param int $priority |
||
| 351 | * @param int $weight |
||
| 352 | * @param int $port |
||
| 353 | * @param string $target |
||
| 354 | * |
||
| 355 | * @return SRV |
||
| 356 | */ |
||
| 357 | 1 | public static function SRV(int $priority, int $weight, int $port, string $target): SRV |
|
| 367 | |||
| 368 | /** |
||
| 369 | * @param IPBlock[] $includedRanges |
||
| 370 | * @param IPBlock[] $excludedRanges |
||
| 371 | * |
||
| 372 | * @return APL |
||
| 373 | */ |
||
| 374 | 2 | public static function APL(array $includedRanges = [], array $excludedRanges = []): APL |
|
| 388 | |||
| 389 | /** |
||
| 390 | * @param int $flag |
||
| 391 | * @param string $tag |
||
| 392 | * @param string $value |
||
| 393 | * |
||
| 394 | * @return CAA |
||
| 395 | */ |
||
| 396 | 1 | public static function CAA(int $flag, string $tag, string $value): CAA |
|
| 405 | |||
| 406 | /** |
||
| 407 | * @param int $subType |
||
| 408 | * @param string $hostname |
||
| 409 | * |
||
| 410 | * @return AFSDB |
||
| 411 | */ |
||
| 412 | public static function AFSDB(int $subType, string $hostname): AFSDB |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @param int $flags |
||
| 423 | * @param int $algorithm |
||
| 424 | * @param string $publicKey |
||
| 425 | * |
||
| 426 | * @return CDNSKEY |
||
| 427 | */ |
||
| 428 | public static function CDNSKEY(int $flags, int $algorithm, string $publicKey): CDNSKEY |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @param int $keyTag |
||
| 440 | * @param int $algorithm |
||
| 441 | * @param string $digest |
||
| 442 | * @param int $digestType |
||
| 443 | * |
||
| 444 | * @return CDS |
||
| 445 | */ |
||
| 446 | public static function CDS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): CDS |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @param int|string $certificateType |
||
| 459 | * @param int $keyTag |
||
| 460 | * @param int $algorithm |
||
| 461 | * @param string $certificate |
||
| 462 | * |
||
| 463 | * @return CERT |
||
| 464 | */ |
||
| 465 | 1 | public static function CERT($certificateType, int $keyTag, int $algorithm, string $certificate): CERT |
|
| 475 | |||
| 476 | 1 | public static function CSYNC(int $soaSerial, int $flags, array $types): CSYNC |
|
| 477 | { |
||
| 478 | 1 | $csync = new CSYNC(); |
|
| 479 | 1 | $csync->setSoaSerial($soaSerial); |
|
| 480 | 1 | $csync->setFlags($flags); |
|
| 481 | 1 | array_map([$csync, 'addType'], $types); |
|
| 482 | |||
| 483 | 1 | return $csync; |
|
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * @param string|null $digest Set to &null if the $identifier and $fqdn are known |
||
| 488 | * @param int $identifierType 16-bit integer |
||
| 489 | * @param string|null $identifier This is ignored if $digest is not &null |
||
| 490 | * @param string|null $fqdn This is ignored if $digest is not &null |
||
| 491 | * |
||
| 492 | * @return DHCID |
||
| 493 | */ |
||
| 494 | 3 | public static function DHCID(?string $digest, int $identifierType, ?string $identifier = null, ?string $fqdn = null): DHCID |
|
| 513 | |||
| 514 | /** |
||
| 515 | * @param int $keyTag |
||
| 516 | * @param int $algorithm |
||
| 517 | * @param string $digest |
||
| 518 | * @param int $digestType |
||
| 519 | * |
||
| 520 | * @return DLV |
||
| 521 | */ |
||
| 522 | public static function DLV(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DLV |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @param int $publicKeyAlgorithm |
||
| 535 | * @param string $hostIdentityTag |
||
| 536 | * @param string $publicKey |
||
| 537 | * @param string[] $rendezvousServers |
||
| 538 | * |
||
| 539 | * @return HIP |
||
| 540 | */ |
||
| 541 | 1 | public static function HIP(int $publicKeyAlgorithm, string $hostIdentityTag, string $publicKey, array $rendezvousServers): HIP |
|
| 551 | |||
| 552 | /** |
||
| 553 | * @param int $precedence an 8-bit unsigned integer |
||
| 554 | * @param string|null $gateway either &null for no gateway, a fully qualified domain name, or an IPv4 or IPv6 address |
||
| 555 | * @param int $algorithm either IPSECKEY::ALGORITHM_NONE, IPSECKEY::ALGORITHM_DSA, IPSECKEY::ALGORITHM_RSA, or IPSECKEY::ALGORITHM_ECDSA |
||
| 556 | * @param string|null $publicKey base64 encoded public key |
||
| 557 | * |
||
| 558 | * @return IPSECKEY |
||
| 559 | */ |
||
| 560 | 6 | public static function IPSECKEY(int $precedence, ?string $gateway, int $algorithm = 0, ?string $publicKey = null): IPSECKEY |
|
| 569 | |||
| 570 | /** |
||
| 571 | * @param int $flags |
||
| 572 | * @param int $protocol |
||
| 573 | * @param int $algorithm |
||
| 574 | * @param string $publicKey |
||
| 575 | * |
||
| 576 | * @return KEY |
||
| 577 | */ |
||
| 578 | public static function KEY(int $flags, int $protocol, int $algorithm, string $publicKey): KEY |
||
| 588 | |||
| 589 | /** |
||
| 590 | * @param int $preference |
||
| 591 | * @param string $exchanger |
||
| 592 | * |
||
| 593 | * @return KX |
||
| 594 | */ |
||
| 595 | public static function KX(int $preference, string $exchanger): KX |
||
| 603 | |||
| 604 | /** |
||
| 605 | * @param int $order |
||
| 606 | * @param int $preference |
||
| 607 | * @param string $flags |
||
| 608 | * @param string $services |
||
| 609 | * @param string $regexp |
||
| 610 | * @param string $replacement |
||
| 611 | * |
||
| 612 | * @return NAPTR |
||
| 613 | */ |
||
| 614 | 2 | public static function NAPTR(int $order, int $preference, string $flags, string $services, string $regexp, string $replacement): NAPTR |
|
| 626 | |||
| 627 | 1 | public static function NSEC3(int $hashAlgorithm, bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextHashedOwnerName, array $types): NSEC3 |
|
| 639 | |||
| 640 | /** |
||
| 641 | * @param int $hashAlgorithm |
||
| 642 | * @param int $flags |
||
| 643 | * @param int $iterations |
||
| 644 | * @param string $salt |
||
| 645 | * |
||
| 646 | * @return NSEC3PARAM |
||
| 647 | */ |
||
| 648 | 1 | public static function NSEC3PARAM(int $hashAlgorithm, int $flags, int $iterations, string $salt): NSEC3PARAM |
|
| 658 | |||
| 659 | public static function RP(string $mboxDomain, string $txtDomain): RP |
||
| 667 | |||
| 668 | /** |
||
| 669 | * @param string $typeCovered |
||
| 670 | * @param int $algorithm |
||
| 671 | * @param int $labels |
||
| 672 | * @param int $originalTtl |
||
| 673 | * @param \DateTime $signatureExpiration |
||
| 674 | * @param \DateTime $signatureInception |
||
| 675 | * @param int $keyTag |
||
| 676 | * @param string $signersName |
||
| 677 | * @param string $signature |
||
| 678 | * |
||
| 679 | * @return SIG |
||
| 680 | */ |
||
| 681 | public static function SIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl, |
||
| 698 | |||
| 699 | /** |
||
| 700 | * @param int $algorithm |
||
| 701 | * @param int $fpType |
||
| 702 | * @param string $fingerprint |
||
| 703 | * |
||
| 704 | * @return SSHFP |
||
| 705 | */ |
||
| 706 | 8 | public static function SSHFP(int $algorithm, int $fpType, string $fingerprint): SSHFP |
|
| 715 | |||
| 716 | /** |
||
| 717 | * @param int $keyTag |
||
| 718 | * @param int $algorithm |
||
| 719 | * @param string $digest |
||
| 720 | * @param int $digestType |
||
| 721 | * |
||
| 722 | * @return TA |
||
| 723 | */ |
||
| 724 | public static function TA(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): TA |
||
| 734 | |||
| 735 | /** |
||
| 736 | * @param string $algorithm |
||
| 737 | * @param \DateTime $inception |
||
| 738 | * @param \DateTime $expiration |
||
| 739 | * @param int $mode |
||
| 740 | * @param int $error |
||
| 741 | * @param string $keyData binary string |
||
| 742 | * @param string $otherData binary string |
||
| 743 | * |
||
| 744 | * @return TKEY |
||
| 745 | */ |
||
| 746 | 1 | public static function TKEY(string $algorithm, \DateTime $inception, \DateTime $expiration, int $mode, int $error, string $keyData, string $otherData = ''): TKEY |
|
| 759 | |||
| 760 | public static function TLSA(): TLSA |
||
| 764 | |||
| 765 | /** |
||
| 766 | * @param string $algorithmName |
||
| 767 | * @param \DateTime $timeSigned |
||
| 768 | * @param int $fudge |
||
| 769 | * @param string $mac |
||
| 770 | * @param int $originalId |
||
| 771 | * @param int $error |
||
| 772 | * @param string $otherData |
||
| 773 | * |
||
| 774 | * @return TSIG |
||
| 775 | */ |
||
| 776 | 1 | public static function TSIG(string $algorithmName, \DateTime $timeSigned, int $fudge, string $mac, int $originalId, int $error, string $otherData): TSIG |
|
| 789 | |||
| 790 | /** |
||
| 791 | * @param int $priority |
||
| 792 | * @param int $weight |
||
| 793 | * @param string $target |
||
| 794 | * |
||
| 795 | * @return URI |
||
| 796 | */ |
||
| 797 | 6 | public static function URI(int $priority, int $weight, string $target): URI |
|
| 806 | } |
||
| 807 |