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 | 2 | 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 | 21 | public function __construct(array $downloadResults) |
|
| 129 | |||
| 130 | public function hasSslChain(): bool |
||
| 138 | |||
| 139 | public function getTestedDomain(): string |
||
| 143 | |||
| 144 | public function getCertificateFields(): array |
||
| 148 | |||
| 149 | public function getCertificateChains(): array |
||
| 153 | |||
| 154 | public function getSerialNumber(): string |
||
| 158 | |||
| 159 | public function hasCrlLink(): bool |
||
| 163 | |||
| 164 | public function getCrlLinks() |
||
| 172 | |||
| 173 | public function getCrl() |
||
| 181 | |||
| 182 | public function isRevoked() |
||
| 186 | |||
| 187 | public function getCrlRevokedTime() |
||
| 193 | |||
| 194 | public function getResolvedIp(): string |
||
| 198 | |||
| 199 | public function getIssuer(): string |
||
| 203 | |||
| 204 | public function getDomain(): string |
||
| 212 | |||
| 213 | public function getCertificateDomain(): string |
||
| 217 | |||
| 218 | public function getSignatureAlgorithm(): string |
||
| 222 | |||
| 223 | public function getAdditionalDomains(): array |
||
| 231 | |||
| 232 | public function getConnectionMeta(): array |
||
| 236 | |||
| 237 | public function validFromDate(): Carbon |
||
| 241 | |||
| 242 | public function expirationDate(): Carbon |
||
| 246 | |||
| 247 | public function isExpired(): bool |
||
| 251 | |||
| 252 | public function isTrusted(): bool |
||
| 256 | |||
| 257 | public function isValid(string $url = null): bool |
||
| 274 | |||
| 275 | public function isValidUntil(Carbon $carbon, string $url = null): bool |
||
| 283 | |||
| 284 | public function appliesToUrl(string $url): bool |
||
| 305 | |||
| 306 | protected function wildcardHostCoversHost(string $wildcardHost, string $host): bool |
||
| 316 | } |
||
| 317 |