Complex classes like RSAKey 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 RSAKey, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | final class RSAKey extends Sequence |
||
26 | { |
||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $values = []; |
||
31 | |||
32 | /** |
||
33 | * @var \Jose\Util\BigInteger |
||
34 | */ |
||
35 | private $modulus; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | private $modulus_length; |
||
41 | |||
42 | /** |
||
43 | * @var \Jose\Util\BigInteger |
||
44 | */ |
||
45 | private $public_exponent; |
||
46 | |||
47 | /** |
||
48 | * @var \Jose\Util\BigInteger|null |
||
49 | */ |
||
50 | private $private_exponent = null; |
||
51 | |||
52 | /** |
||
53 | * @var \Jose\Util\BigInteger[] |
||
54 | */ |
||
55 | private $primes = []; |
||
56 | |||
57 | /** |
||
58 | * @var \Jose\Util\BigInteger[] |
||
59 | */ |
||
60 | private $exponents = []; |
||
61 | |||
62 | /** |
||
63 | * @var \Jose\Util\BigInteger|null |
||
64 | */ |
||
65 | private $coefficient = null; |
||
66 | |||
67 | |||
68 | /** |
||
69 | * @param \Jose\Object\JWKInterface|string|array $data |
||
70 | */ |
||
71 | public function __construct($data) |
||
87 | |||
88 | /** |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function isPublic() |
||
95 | |||
96 | /** |
||
97 | * @return bool |
||
98 | */ |
||
99 | public function isPrivate() |
||
103 | |||
104 | /** |
||
105 | * @return \Jose\Util\BigInteger |
||
106 | */ |
||
107 | public function getModulus() |
||
111 | |||
112 | /** |
||
113 | * @return int |
||
114 | */ |
||
115 | public function getModulusLength() |
||
119 | |||
120 | /** |
||
121 | * @return \Jose\Util\BigInteger |
||
122 | */ |
||
123 | public function getExponent() |
||
132 | |||
133 | /** |
||
134 | * @return \Jose\Util\BigInteger |
||
135 | */ |
||
136 | public function getPublicExponent() |
||
140 | |||
141 | /** |
||
142 | * @return \Jose\Util\BigInteger |
||
143 | */ |
||
144 | public function getPrivateExponent() |
||
148 | |||
149 | /** |
||
150 | * @return \Jose\Util\BigInteger[] |
||
151 | */ |
||
152 | public function getPrimes() |
||
156 | |||
157 | /** |
||
158 | * @return \Jose\Util\BigInteger[] |
||
159 | */ |
||
160 | public function getExponents() |
||
164 | |||
165 | /** |
||
166 | * @return \Jose\Util\BigInteger|null |
||
167 | */ |
||
168 | public function getCoefficient() |
||
172 | |||
173 | /** |
||
174 | * @param string $value |
||
175 | * |
||
176 | * @return \Jose\Util\BigInteger |
||
177 | */ |
||
178 | private function convertBase64StringToBigInteger($value) |
||
182 | |||
183 | /** |
||
184 | * @param $data |
||
185 | * |
||
186 | * @throws \Exception |
||
187 | * @throws \FG\ASN1\Exception\ParserException |
||
188 | * |
||
189 | * @return array |
||
190 | */ |
||
191 | private function loadPEM($data) |
||
220 | |||
221 | /** |
||
222 | * @param array $jwk |
||
223 | */ |
||
224 | private function loadJWK(array $jwk) |
||
237 | |||
238 | /** |
||
239 | * This method adds Chinese Remainder Theorem (CRT) parameters if primes 'p' and 'q' are available. |
||
240 | */ |
||
241 | private function populateCRT() |
||
259 | |||
260 | /** |
||
261 | * @throws \Exception |
||
262 | */ |
||
263 | private function initPublicKey() |
||
279 | |||
280 | private function initPrivateKey() |
||
312 | |||
313 | /** |
||
314 | * @param string $value |
||
315 | * |
||
316 | * @return string |
||
317 | */ |
||
318 | private function fromBase64ToInteger($value) |
||
322 | |||
323 | /** |
||
324 | * @param \Jose\KeyConverter\RSAKey $private |
||
325 | * |
||
326 | * @return \Jose\KeyConverter\RSAKey |
||
327 | */ |
||
328 | public static function toPublic(RSAKey $private) |
||
340 | |||
341 | public function __toString() |
||
345 | |||
346 | /** |
||
347 | * @return array |
||
348 | */ |
||
349 | public function toArray() |
||
353 | |||
354 | /** |
||
355 | * @return string |
||
356 | */ |
||
357 | public function toDER() |
||
361 | |||
362 | /** |
||
363 | * @return string |
||
364 | */ |
||
365 | public function toPEM() |
||
373 | |||
374 | private function populateBigIntegers() |
||
394 | } |
||
395 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.