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 | * @param \Jose\Object\JWKInterface|string|array $data |
||
| 34 | */ |
||
| 35 | public function __construct($data) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return bool |
||
| 52 | */ |
||
| 53 | public function isPublic() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | public function isPrivate() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @return \Jose\Util\BigInteger |
||
| 68 | */ |
||
| 69 | public function getModulus() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return int |
||
| 76 | */ |
||
| 77 | public function getModulusLength() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return \Jose\Util\BigInteger |
||
| 84 | */ |
||
| 85 | public function getExponent() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @return \Jose\Util\BigInteger |
||
| 95 | */ |
||
| 96 | public function getPublicExponent() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return \Jose\Util\BigInteger |
||
| 103 | */ |
||
| 104 | public function getPrivateExponent() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return \Jose\Util\BigInteger[] |
||
| 113 | */ |
||
| 114 | public function getPrimes() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return \Jose\Util\BigInteger[] |
||
| 128 | */ |
||
| 129 | public function getExponents() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return \Jose\Util\BigInteger|null |
||
| 143 | */ |
||
| 144 | public function getCoefficient() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param string $value |
||
| 153 | * |
||
| 154 | * @return \Jose\Util\BigInteger |
||
| 155 | */ |
||
| 156 | private function convertBase64StringToBigInteger($value) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param $data |
||
| 163 | * |
||
| 164 | * @throws \Exception |
||
| 165 | * @throws \FG\ASN1\Exception\ParserException |
||
| 166 | * |
||
| 167 | * @return array |
||
| 168 | */ |
||
| 169 | private function loadPEM($data) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param array $jwk |
||
| 201 | */ |
||
| 202 | private function loadJWK(array $jwk) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @throws \Exception |
||
| 220 | */ |
||
| 221 | private function initPublicKey() |
||
| 237 | |||
| 238 | private function initPrivateKey() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @param string $value |
||
| 273 | * |
||
| 274 | * @return string |
||
| 275 | */ |
||
| 276 | private function fromBase64ToInteger($value) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @param \Jose\KeyConverter\RSAKey $private |
||
| 283 | * |
||
| 284 | * @return \Jose\KeyConverter\RSAKey |
||
| 285 | */ |
||
| 286 | public static function toPublic(RSAKey $private) |
||
| 298 | |||
| 299 | public function __toString() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * @return array |
||
| 306 | */ |
||
| 307 | public function toArray() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @return string |
||
| 314 | */ |
||
| 315 | public function toDER() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @return string |
||
| 322 | */ |
||
| 323 | public function toPEM() |
||
| 331 | } |
||
| 332 |