Complex classes like ECDHES 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 ECDHES, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | final class ECDHES implements KeyAgreement |
||
28 | { |
||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function allowedKeyTypes(): array |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | public function getAgreementKey(int $encryption_key_length, string $algorithm, JWK $recipient_key, array $complete_header = [], array &$additional_header_values = []): string |
||
55 | |||
56 | /** |
||
57 | * @param JWK $recipient_key |
||
58 | * @param array $additional_header_values |
||
59 | * |
||
60 | * @return JWK[] |
||
61 | */ |
||
62 | private function getKeysFromPublicKey(JWK $recipient_key, array &$additional_header_values): array |
||
85 | |||
86 | /** |
||
87 | * @param JWK $recipient_key |
||
88 | * @param array $complete_header |
||
89 | * |
||
90 | * @return JWK[] |
||
91 | */ |
||
92 | private function getKeysFromPrivateKeyAndHeader(JWK $recipient_key, array $complete_header): array |
||
103 | |||
104 | /** |
||
105 | * @param JWK $private_key |
||
106 | * @param JWK $public_key |
||
107 | * |
||
108 | * @throws \InvalidArgumentException |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function calculateAgreementKey(JWK $private_key, JWK $public_key): string |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function name(): string |
||
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | public function getKeyManagementMode(): string |
||
153 | |||
154 | /** |
||
155 | * @param array $complete_header |
||
156 | * |
||
157 | * @return JWK |
||
158 | */ |
||
159 | private function getPublicKey(array $complete_header) |
||
173 | |||
174 | /** |
||
175 | * @param JWK $key |
||
176 | * @param bool $is_private |
||
177 | */ |
||
178 | private function checkKey(JWK $key, $is_private) |
||
209 | |||
210 | /** |
||
211 | * @param string $crv |
||
212 | * |
||
213 | * @throws \InvalidArgumentException |
||
214 | * |
||
215 | * @return Curve |
||
216 | */ |
||
217 | private function getCurve(string $crv): Curve |
||
230 | |||
231 | /** |
||
232 | * @param string $value |
||
233 | * |
||
234 | * @return \GMP |
||
235 | */ |
||
236 | private function convertBase64ToGmp(string $value): \GMP |
||
242 | |||
243 | /** |
||
244 | * @param \GMP $dec |
||
245 | * |
||
246 | * @return string |
||
247 | */ |
||
248 | private function convertDecToBin(\GMP $dec): string |
||
262 | |||
263 | /** |
||
264 | * @param string $crv The curve |
||
265 | * |
||
266 | * @return JWK |
||
267 | */ |
||
268 | public function createECKey(string $crv): JWK |
||
282 | |||
283 | /** |
||
284 | * @param string $curve The curve |
||
285 | * |
||
286 | * @return JWK |
||
287 | */ |
||
288 | public static function createOKPKey(string $curve): JWK |
||
313 | } |
||
314 |