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 | /** @var bool */ |
||
11 | protected $trusted; |
||
12 | |||
13 | /** @var bool */ |
||
14 | protected $revoked; |
||
15 | |||
16 | /** @var string */ |
||
17 | protected $ip; |
||
18 | |||
19 | /** @var BigInteger */ |
||
20 | protected $serial; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $inputDomain; |
||
24 | |||
25 | /** @var string */ |
||
26 | protected $testedDomain; |
||
27 | |||
28 | /** @var array */ |
||
29 | protected $certificateFields = []; |
||
30 | |||
31 | /** @var array */ |
||
32 | protected $certificateChains = []; |
||
33 | |||
34 | /** @var array */ |
||
35 | protected $connectionMeta = []; |
||
36 | |||
37 | /** @var SslRevocationList */ |
||
38 | protected $crl; |
||
39 | |||
40 | /** @var array */ |
||
41 | protected $crlLinks = []; |
||
42 | |||
43 | /** @var Carbon */ |
||
44 | protected $revokedTime; |
||
45 | |||
46 | public static function createForHostName(string $url, int $timeout = 30): SslCertificate |
||
52 | |||
53 | private static function extractCrlLinks($rawCrlPoints): string |
||
60 | |||
61 | private static function parseCrlLinks($rawCrlInput): array |
||
75 | |||
76 | private function getRevokedDate() |
||
84 | |||
85 | private function isClrRevoked() |
||
100 | |||
101 | private static function parseCertChains(array $chains): array |
||
110 | |||
111 | public function __construct(array $downloadResults) |
||
129 | |||
130 | public function hasSslChain(): bool |
||
138 | |||
139 | public function getCertificateFields(): array |
||
143 | |||
144 | public function getCertificateChains(): array |
||
148 | |||
149 | public function getSerialNumber(): string |
||
153 | |||
154 | public function hasCrlLink(): bool |
||
158 | |||
159 | public function getCrlLinks() |
||
167 | |||
168 | public function getCrl() |
||
176 | |||
177 | public function isRevoked() |
||
181 | |||
182 | public function getCrlRevokedTime() |
||
188 | |||
189 | public function getResolvedIp(): string |
||
193 | |||
194 | public function getIssuer(): string |
||
198 | |||
199 | public function getDomain(): string |
||
208 | |||
209 | public function getTestedDomain(): string |
||
213 | |||
214 | public function getInputDomain(): string |
||
218 | |||
219 | public function getCertificateDomain(): string |
||
223 | |||
224 | public function getAdditionalDomains(): array |
||
232 | |||
233 | public function getSignatureAlgorithm(): string |
||
237 | |||
238 | public function getConnectionMeta(): array |
||
242 | |||
243 | public function validFromDate(): Carbon |
||
247 | |||
248 | public function expirationDate(): Carbon |
||
252 | |||
253 | public function isExpired(): bool |
||
257 | |||
258 | public function isTrusted(): bool |
||
262 | |||
263 | public function isValid(string $url = null): bool |
||
280 | |||
281 | public function isValidUntil(Carbon $carbon, string $url = null): bool |
||
289 | |||
290 | public function isValidDate(Carbon $carbon): bool |
||
298 | |||
299 | public function isSelfSigned(): bool |
||
322 | |||
323 | public function appliesToUrl(string $url): bool |
||
344 | |||
345 | protected function wildcardHostCoversHost(string $wildcardHost, string $host): bool |
||
355 | } |
||
356 |