Complex classes like JWE 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 JWE, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | final class JWE implements JWEInterface |
||
| 20 | { |
||
| 21 | use JWT; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var \Jose\Object\RecipientInterface[] |
||
| 25 | */ |
||
| 26 | private $recipients = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string|null |
||
| 30 | */ |
||
| 31 | private $ciphertext = null; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string|null |
||
| 35 | */ |
||
| 36 | private $iv = null; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string|null |
||
| 40 | */ |
||
| 41 | private $aad = null; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string|null |
||
| 45 | */ |
||
| 46 | private $tag = null; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var array |
||
| 50 | */ |
||
| 51 | private $shared_headers = []; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var array |
||
| 55 | */ |
||
| 56 | private $shared_protected_headers = []; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string|null |
||
| 60 | */ |
||
| 61 | private $encoded_shared_protected_headers = null; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string|null |
||
| 65 | */ |
||
| 66 | private $content_encryption_key = null; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritdoc} |
||
| 70 | */ |
||
| 71 | public function countRecipients() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc} |
||
| 78 | */ |
||
| 79 | public function addRecipient(RecipientInterface $recipient) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | public function getRecipients() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * {@inheritdoc} |
||
| 97 | */ |
||
| 98 | public function getRecipient($id) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * {@inheritdoc} |
||
| 108 | */ |
||
| 109 | public function getCiphertext() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * {@inheritdoc} |
||
| 116 | */ |
||
| 117 | public function withCiphertext($ciphertext) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * {@inheritdoc} |
||
| 127 | */ |
||
| 128 | public function getAAD() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | public function withAAD($aad) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * {@inheritdoc} |
||
| 146 | */ |
||
| 147 | public function getIV() |
||
| 151 | |||
| 152 | /** |
||
| 153 | * {@inheritdoc} |
||
| 154 | */ |
||
| 155 | public function withIV($iv) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * {@inheritdoc} |
||
| 165 | */ |
||
| 166 | public function getTag() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * {@inheritdoc} |
||
| 173 | */ |
||
| 174 | public function withTag($tag) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * {@inheritdoc} |
||
| 184 | */ |
||
| 185 | public function getEncodedSharedProtectedHeaders() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * {@inheritdoc} |
||
| 192 | */ |
||
| 193 | public function withEncodedSharedProtectedHeaders($encoded_shared_protected_headers) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * {@inheritdoc} |
||
| 203 | */ |
||
| 204 | public function getSharedProtectedHeaders() |
||
| 208 | |||
| 209 | /** |
||
| 210 | * {@inheritdoc} |
||
| 211 | */ |
||
| 212 | public function withSharedProtectedHeaders(array $shared_protected_headers) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritdoc} |
||
| 222 | */ |
||
| 223 | public function withSharedProtectedHeader($key, $value) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * {@inheritdoc} |
||
| 233 | */ |
||
| 234 | public function getSharedProtectedHeader($key) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * {@inheritdoc} |
||
| 244 | */ |
||
| 245 | public function hasSharedProtectedHeader($key) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritdoc} |
||
| 252 | */ |
||
| 253 | public function withSharedHeaders(array $shared_headers) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * {@inheritdoc} |
||
| 263 | */ |
||
| 264 | public function withSharedHeader($key, $value) |
||
| 271 | |||
| 272 | /** |
||
| 273 | * {@inheritdoc} |
||
| 274 | */ |
||
| 275 | public function getSharedHeaders() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * {@inheritdoc} |
||
| 282 | */ |
||
| 283 | public function getSharedHeader($key) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * {@inheritdoc} |
||
| 293 | */ |
||
| 294 | public function hasSharedHeader($key) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * {@inheritdoc} |
||
| 301 | */ |
||
| 302 | public function toCompactJSON($id) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * {@inheritdoc} |
||
| 322 | */ |
||
| 323 | public function toFlattenedJSON($id) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * {@inheritdoc} |
||
| 357 | */ |
||
| 358 | public function toJSON() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * {@inheritdoc} |
||
| 395 | */ |
||
| 396 | public function getContentEncryptionKey() |
||
| 400 | |||
| 401 | /** |
||
| 402 | * {@inheritdoc} |
||
| 403 | */ |
||
| 404 | public function withContentEncryptionKey($content_encryption_key) |
||
| 411 | } |
||
| 412 |