Complex classes like SslCertificate 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 SslCertificate, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class SslCertificate |
||
9 | { |
||
10 | use Macroable; |
||
11 | |||
12 | /** @var array */ |
||
13 | protected $rawCertificateFields = []; |
||
14 | |||
15 | /** @var string */ |
||
16 | protected $fingerprint = ''; |
||
17 | |||
18 | /** @var string */ |
||
19 | private $fingerprintSha256 = ''; |
||
20 | |||
21 | /** @var string */ |
||
22 | private $remoteAddress = ''; |
||
23 | |||
24 | public static function download(): Downloader |
||
28 | |||
29 | public static function createForHostName(string $url, int $timeout = 30): self |
||
33 | |||
34 | public function __construct( |
||
48 | |||
49 | public function getRawCertificateFields(): array |
||
53 | |||
54 | public function getIssuer(): string |
||
58 | |||
59 | public function getDomain(): string |
||
75 | |||
76 | public function getSignatureAlgorithm(): string |
||
80 | |||
81 | public function getFingerprint(): string |
||
85 | |||
86 | /** |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getFingerprintSha256(): string |
||
93 | |||
94 | public function getAdditionalDomains(): array |
||
102 | |||
103 | public function validFromDate(): Carbon |
||
107 | |||
108 | public function expirationDate(): Carbon |
||
112 | |||
113 | public function isExpired(): bool |
||
117 | |||
118 | public function isValid(string $url = null) |
||
130 | |||
131 | public function isSelfSigned(): bool |
||
135 | |||
136 | public function usesSha1Hash(): bool |
||
150 | |||
151 | public function isValidUntil(Carbon $carbon, string $url = null): bool |
||
159 | |||
160 | public function daysUntilExpirationDate(): int |
||
168 | |||
169 | public function getDomains(): array |
||
177 | |||
178 | public function appliesToUrl(string $url): bool |
||
201 | |||
202 | protected function wildcardHostCoversHost(string $wildcardHost, string $host): bool |
||
222 | |||
223 | public function getRawCertificateFieldsJson(): string |
||
227 | |||
228 | public function getHash(): string |
||
232 | |||
233 | public function getRemoteAddress(): string |
||
237 | |||
238 | public function __toString(): string |
||
242 | |||
243 | public function containsDomain(string $domain): bool |
||
259 | |||
260 | public function isPreCertificate(): bool |
||
272 | } |
||
273 |