Complex classes like ECKey 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 ECKey, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | final class ECKey |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | private $values = []; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * ECKey constructor. |
||
| 35 | * |
||
| 36 | * @param array $data |
||
| 37 | */ |
||
| 38 | private function __construct(array $data) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param JWK $jwk |
||
| 45 | * |
||
| 46 | * @return ECKey |
||
| 47 | */ |
||
| 48 | public static function createFromJWK(JWK $jwk): ECKey |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $pem |
||
| 55 | * |
||
| 56 | * @return ECKey |
||
| 57 | */ |
||
| 58 | public static function createFromPEM(string $pem): ECKey |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $data |
||
| 67 | * |
||
| 68 | * @return array |
||
| 69 | * |
||
| 70 | * @throws \Exception |
||
| 71 | */ |
||
| 72 | private static function loadPEM(string $data): array |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param array $children |
||
| 96 | * |
||
| 97 | * @return array |
||
| 98 | */ |
||
| 99 | private static function loadPKCS8(array $children): array |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @param array $children |
||
| 112 | * |
||
| 113 | * @return array |
||
| 114 | */ |
||
| 115 | private static function loadPublicPEM(array $children): array |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param string $oid |
||
| 151 | * |
||
| 152 | * @return string |
||
| 153 | */ |
||
| 154 | private static function getCurve(string $oid): string |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @return array |
||
| 167 | */ |
||
| 168 | private static function getSupportedCurves(): array |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param object $children |
||
| 179 | */ |
||
| 180 | private static function verifyVersion(Object $children) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param object $children |
||
| 189 | * @param string|null $x |
||
| 190 | * @param string|null $y |
||
| 191 | */ |
||
| 192 | private static function getXAndY(Object $children, ?string &$x, ?string &$y) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param object $children |
||
| 214 | * |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | private static function getD(Object $children): string |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @param array $children |
||
| 228 | * |
||
| 229 | * @return array |
||
| 230 | */ |
||
| 231 | private static function loadPrivatePEM(array $children): array |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @param array $children |
||
| 259 | * |
||
| 260 | * @return bool |
||
| 261 | */ |
||
| 262 | private static function isPKCS8(array $children): bool |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param ECKey $private |
||
| 280 | * |
||
| 281 | * @return ECKey |
||
| 282 | */ |
||
| 283 | public static function toPublic(ECKey $private): ECKey |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return array |
||
| 295 | */ |
||
| 296 | public function toArray() |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param array $jwk |
||
| 303 | */ |
||
| 304 | private function loadJWK(array $jwk) |
||
| 323 | } |
||
| 324 |