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 |
||
20 | class Factory |
||
21 | { |
||
22 | /** |
||
23 | * Creates a new RData object from a name. |
||
24 | * |
||
25 | * @throws UnsupportedTypeException |
||
26 | */ |
||
27 | 37 | public static function newRdataFromName(string $name): RdataInterface |
|
37 | |||
38 | /** |
||
39 | * @throws UnsupportedTypeException |
||
40 | */ |
||
41 | 11 | public static function newRdataFromId(int $id): RdataInterface |
|
45 | |||
46 | 39 | public static function isTypeImplemented(string $name): bool |
|
50 | |||
51 | 3 | public static function isTypeCodeImplemented(int $typeCode): bool |
|
59 | |||
60 | /** |
||
61 | * @throws ParseException|UnsupportedTypeException |
||
62 | */ |
||
63 | 28 | public static function textToRdataType(string $type, string $text): RdataInterface |
|
103 | |||
104 | /** |
||
105 | * Get the fully qualified class name of the RData class for $type. |
||
106 | */ |
||
107 | 39 | public static function getRdataClassName(string $type): string |
|
111 | |||
112 | /** |
||
113 | * Create a new AAAA R-Data object. |
||
114 | */ |
||
115 | 13 | public static function AAAA(string $address): AAAA |
|
122 | |||
123 | /** |
||
124 | * Create a new A R-Data object. |
||
125 | */ |
||
126 | 16 | public static function A(string $address): A |
|
133 | |||
134 | /** |
||
135 | * Create a new CNAME object. |
||
136 | */ |
||
137 | 10 | public static function CNAME(string $cname): CNAME |
|
144 | |||
145 | 10 | public static function HINFO(string $cpu, string $os): HINFO |
|
153 | |||
154 | 12 | public static function MX(int $preference, string $exchange): MX |
|
162 | |||
163 | 15 | public static function SOA(string $mname, string $rname, int $serial, int $refresh, int $retry, int $expire, int $minimum): SOA |
|
176 | |||
177 | 14 | public static function NS(string $nsdname): NS |
|
184 | |||
185 | 11 | public static function TXT(string $text): TXT |
|
192 | |||
193 | 2 | public static function SPF(string $text): SPF |
|
200 | |||
201 | 10 | public static function DNAME(string $target): DNAME |
|
208 | |||
209 | /** |
||
210 | * @param float $alt |
||
211 | * @param float $size |
||
212 | * @param float $hp |
||
213 | * @param float $vp |
||
214 | */ |
||
215 | 11 | public static function LOC(float $lat, float $lon, $alt = 0.0, $size = 1.0, $hp = 10000.0, $vp = 10.0): LOC |
|
227 | |||
228 | 2 | public static function PTR(string $target): PTR |
|
235 | |||
236 | 1 | public static function DNSKEY(int $flags, int $algorithm, string $publicKey): DNSKEY |
|
245 | |||
246 | 1 | public static function DS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DS |
|
256 | |||
257 | 1 | public static function NSEC(string $nextDomainName, array $types): NSEC |
|
265 | |||
266 | 11 | public static function RRSIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl, |
|
283 | |||
284 | 11 | public static function SRV(int $priority, int $weight, int $port, string $target): SRV |
|
294 | |||
295 | /** |
||
296 | * @param IPBlock[] $includedRanges |
||
297 | * @param IPBlock[] $excludedRanges |
||
298 | */ |
||
299 | 2 | public static function APL(array $includedRanges = [], array $excludedRanges = []): APL |
|
313 | |||
314 | 1 | public static function CAA(int $flag, string $tag, string $value): CAA |
|
323 | |||
324 | 1 | public static function AFSDB(int $subType, string $hostname): AFSDB |
|
332 | |||
333 | 1 | public static function CDNSKEY(int $flags, int $algorithm, string $publicKey): CDNSKEY |
|
342 | |||
343 | 1 | public static function CDS(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): CDS |
|
353 | |||
354 | /** |
||
355 | * @param int|string $certificateType |
||
356 | */ |
||
357 | 1 | public static function CERT($certificateType, int $keyTag, int $algorithm, string $certificate): CERT |
|
367 | |||
368 | 1 | public static function CSYNC(int $soaSerial, int $flags, array $types): CSYNC |
|
377 | |||
378 | /** |
||
379 | * @param string|null $digest Set to &null if the $identifier and $fqdn are known |
||
380 | * @param int $identifierType 16-bit integer |
||
381 | * @param string|null $identifier This is ignored if $digest is not &null |
||
382 | * @param string|null $fqdn This is ignored if $digest is not &null |
||
383 | */ |
||
384 | 4 | public static function DHCID(?string $digest, int $identifierType, ?string $identifier = null, ?string $fqdn = null): DHCID |
|
403 | |||
404 | 1 | public static function DLV(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): DLV |
|
414 | |||
415 | /** |
||
416 | * @param string[] $rendezvousServers |
||
417 | */ |
||
418 | 1 | public static function HIP(int $publicKeyAlgorithm, string $hostIdentityTag, string $publicKey, array $rendezvousServers): HIP |
|
428 | |||
429 | /** |
||
430 | * @param int $precedence an 8-bit unsigned integer |
||
431 | * @param string|null $gateway either &null for no gateway, a fully qualified domain name, or an IPv4 or IPv6 address |
||
432 | * @param int $algorithm either IPSECKEY::ALGORITHM_NONE, IPSECKEY::ALGORITHM_DSA, IPSECKEY::ALGORITHM_RSA, or IPSECKEY::ALGORITHM_ECDSA |
||
433 | * @param string|null $publicKey base64 encoded public key |
||
434 | */ |
||
435 | 6 | public static function IPSECKEY(int $precedence, ?string $gateway, int $algorithm = 0, ?string $publicKey = null): IPSECKEY |
|
444 | |||
445 | 1 | public static function KEY(int $flags, int $protocol, int $algorithm, string $publicKey): KEY |
|
455 | |||
456 | 1 | public static function KX(int $preference, string $exchanger): KX |
|
464 | |||
465 | 4 | public static function NAPTR(int $order, int $preference, string $flags, string $services, string $regexp, string $replacement): NAPTR |
|
477 | |||
478 | 2 | public static function NSEC3(bool $unsignedDelegationsCovered, int $iterations, string $salt, string $nextOwnerName, array $types): NSEC3 |
|
490 | |||
491 | 2 | public static function NSEC3PARAM(int $hashAlgorithm, int $flags, int $iterations, string $salt): NSEC3PARAM |
|
501 | |||
502 | 2 | public static function RP(string $mboxDomain, string $txtDomain): RP |
|
510 | |||
511 | 1 | public static function SIG(string $typeCovered, int $algorithm, int $labels, int $originalTtl, |
|
528 | |||
529 | 5 | public static function SSHFP(int $algorithm, int $fpType, string $fingerprint): SSHFP |
|
538 | |||
539 | 1 | public static function TA(int $keyTag, int $algorithm, string $digest, int $digestType = DS::DIGEST_SHA1): TA |
|
549 | |||
550 | /** |
||
551 | * @param string $keyData binary string |
||
552 | * @param string $otherData binary string |
||
553 | */ |
||
554 | 1 | public static function TKEY(string $algorithm, \DateTime $inception, \DateTime $expiration, int $mode, int $error, string $keyData, string $otherData = ''): TKEY |
|
567 | |||
568 | 1 | public static function TLSA(int $certificateUsage, int $selector, int $matchingType, string $certificateAssociationData): TLSA |
|
578 | |||
579 | 1 | public static function TSIG(string $algorithmName, \DateTime $timeSigned, int $fudge, string $mac, int $originalId, int $error, string $otherData): TSIG |
|
592 | |||
593 | 6 | public static function URI(int $priority, int $weight, string $target): URI |
|
602 | } |
||
603 |