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 |
||
29 | final class ECKey |
||
30 | { |
||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $values = []; |
||
35 | |||
36 | /** |
||
37 | * ECKey constructor. |
||
38 | * |
||
39 | * @param array $data |
||
40 | */ |
||
41 | private function __construct(array $data) |
||
45 | |||
46 | /** |
||
47 | * @param JWK $jwk |
||
48 | * |
||
49 | * @return ECKey |
||
50 | */ |
||
51 | public static function createFromJWK(JWK $jwk): ECKey |
||
55 | |||
56 | /** |
||
57 | * @param string $pem |
||
58 | * |
||
59 | * @return ECKey |
||
60 | */ |
||
61 | public static function createFromPEM(string $pem): ECKey |
||
67 | |||
68 | /** |
||
69 | * @param string $data |
||
70 | * |
||
71 | * @return array |
||
72 | * |
||
73 | * @throws \Exception |
||
74 | */ |
||
75 | private static function loadPEM(string $data): array |
||
96 | |||
97 | /** |
||
98 | * @param ASNObject[] $children |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | private static function loadPKCS8(array $children): array |
||
112 | |||
113 | /** |
||
114 | * @param ASNObject[] $children |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | private static function loadPublicPEM(array $children): array |
||
151 | |||
152 | /** |
||
153 | * @param string $oid |
||
154 | * |
||
155 | * @return string |
||
156 | */ |
||
157 | private static function getCurve(string $oid): string |
||
167 | |||
168 | /** |
||
169 | * @return array |
||
170 | */ |
||
171 | private static function getSupportedCurves(): array |
||
179 | |||
180 | /** |
||
181 | * @param ASNObject $children |
||
182 | */ |
||
183 | private static function verifyVersion(ASNObject $children) |
||
189 | |||
190 | /** |
||
191 | * @param ASNObject $children |
||
192 | * @param string|null $x |
||
193 | * @param string|null $y |
||
194 | */ |
||
195 | private static function getXAndY(ASNObject $children, ?string &$x, ?string &$y) |
||
214 | |||
215 | /** |
||
216 | * @param ASNObject $children |
||
217 | * |
||
218 | * @return string |
||
219 | */ |
||
220 | private static function getD(ASNObject $children): string |
||
228 | |||
229 | /** |
||
230 | * @param array $children |
||
231 | * |
||
232 | * @return array |
||
233 | */ |
||
234 | private static function loadPrivatePEM(array $children): array |
||
259 | |||
260 | /** |
||
261 | * @param ASNObject[] $children |
||
262 | * |
||
263 | * @return bool |
||
264 | */ |
||
265 | private static function isPKCS8(array $children): bool |
||
280 | |||
281 | /** |
||
282 | * @param ECKey $private |
||
283 | * |
||
284 | * @return ECKey |
||
285 | */ |
||
286 | public static function toPublic(ECKey $private): ECKey |
||
295 | |||
296 | /** |
||
297 | * @return array |
||
298 | */ |
||
299 | public function toArray() |
||
303 | |||
304 | /** |
||
305 | * @param array $jwk |
||
306 | */ |
||
307 | private function loadJWK(array $jwk) |
||
326 | } |
||
327 |