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 |
||
| 10 | class SslCertificate |
||
| 11 | { |
||
| 12 | |||
| 13 | /** @var bool */ |
||
| 14 | protected $trusted; |
||
| 15 | |||
| 16 | /** @var bool */ |
||
| 17 | protected $revoked; |
||
| 18 | |||
| 19 | /** @var string */ |
||
| 20 | protected $ip; |
||
| 21 | |||
| 22 | /** @var BigInteger */ |
||
| 23 | protected $serial; |
||
| 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 |
||
| 59 | |||
| 60 | private static function parseCrlLinks($rawCrlInput): array |
||
| 61 | { |
||
| 62 | $crlLinks = []; |
||
| 63 | $crlRawItems = explode('Full Name:', $rawCrlInput); |
||
| 64 | // Remove the stuff before the first 'Full Name:' item |
||
| 65 | array_splice($crlRawItems, 0, 1); |
||
| 66 | foreach ($crlRawItems as $item) { |
||
| 67 | $crlLink = self::extractCrlLinks($item); |
||
| 68 | array_push($crlLinks, $crlLink); |
||
| 69 | unset($crlLink); |
||
| 70 | } |
||
| 71 | return $crlLinks; |
||
| 72 | } |
||
| 73 | |||
| 74 | private function getRevokedDate() |
||
| 82 | |||
| 83 | private function isClrRevoked() |
||
| 96 | |||
| 97 | private static function parseCertChains(array $chains): array |
||
| 105 | |||
| 106 | public function __construct(array $downloadResults) |
||
| 123 | |||
| 124 | public function hasSslChain(): bool |
||
| 131 | |||
| 132 | public function getTestedDomain(): string |
||
| 136 | |||
| 137 | public function getCertificateFields(): array |
||
| 141 | |||
| 142 | public function getCertificateChains(): array |
||
| 146 | |||
| 147 | public function getSerialNumber(): string |
||
| 151 | |||
| 152 | public function hasCrlLink(): bool |
||
| 156 | |||
| 157 | public function getCrlLinks() |
||
| 164 | |||
| 165 | public function getCrl() |
||
| 173 | |||
| 174 | public function isRevoked() |
||
| 178 | |||
| 179 | public function getCrlRevokedTime() |
||
| 186 | |||
| 187 | public function getResolvedIp(): string |
||
| 191 | |||
| 192 | public function getIssuer(): string |
||
| 196 | |||
| 197 | public function getDomain(): string |
||
| 201 | |||
| 202 | public function getSignatureAlgorithm(): string |
||
| 206 | |||
| 207 | public function getAdditionalDomains(): array |
||
| 215 | |||
| 216 | public function getConnectionMeta(): array |
||
| 220 | |||
| 221 | public function validFromDate(): Carbon |
||
| 225 | |||
| 226 | public function expirationDate(): Carbon |
||
| 230 | |||
| 231 | public function isExpired(): bool |
||
| 235 | |||
| 236 | public function isTrusted(): bool |
||
| 240 | |||
| 241 | public function isValid(string $url = null): bool |
||
| 258 | |||
| 259 | public function isValidUntil(Carbon $carbon, string $url = null): bool |
||
| 267 | |||
| 268 | public function appliesToUrl(string $url): bool |
||
| 286 | |||
| 287 | protected function wildcardHostCoversHost(string $wildcardHost, string $host): bool |
||
| 301 | } |
||
| 302 |