| Conditions | 11 |
| Paths | 81 |
| Total Lines | 31 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 100 | public function unserialize(string $input): JWE |
||
| 101 | { |
||
| 102 | $data = $this->jsonConverter->decode($input); |
||
| 103 | if (!is_array($data) || !array_key_exists('ciphertext', $data) || !array_key_exists('recipients', $data)) { |
||
| 104 | throw new \InvalidArgumentException('Unsupported input.'); |
||
| 105 | } |
||
| 106 | |||
| 107 | $ciphertext = Base64Url::decode($data['ciphertext']); |
||
| 108 | $iv = Base64Url::decode($data['iv']); |
||
| 109 | $tag = Base64Url::decode($data['tag']); |
||
| 110 | $aad = array_key_exists('aad', $data) ? Base64Url::decode($data['aad']) : null; |
||
| 111 | $encodedSharedProtectedHeader = array_key_exists('protected', $data) ? $data['protected'] : null; |
||
| 112 | $sharedProtectedHeader = $encodedSharedProtectedHeader ? $this->jsonConverter->decode(Base64Url::decode($encodedSharedProtectedHeader)) : []; |
||
| 113 | $sharedHeader = array_key_exists('unprotected', $data) ? $data['unprotected'] : []; |
||
| 114 | $recipients = []; |
||
| 115 | foreach ($data['recipients'] as $recipient) { |
||
| 116 | $encryptedKey = array_key_exists('encrypted_key', $recipient) ? Base64Url::decode($recipient['encrypted_key']) : null; |
||
| 117 | $header = array_key_exists('header', $recipient) ? $recipient['header'] : []; |
||
| 118 | $recipients[] = Recipient::create($header, $encryptedKey); |
||
| 119 | } |
||
| 120 | |||
| 121 | return JWE::create( |
||
| 122 | $ciphertext, |
||
| 123 | $iv, |
||
| 124 | $tag, |
||
| 125 | $aad, |
||
| 126 | $sharedHeader, |
||
| 127 | $sharedProtectedHeader, |
||
| 128 | $encodedSharedProtectedHeader, |
||
| 129 | $recipients); |
||
| 130 | } |
||
| 131 | } |
||
| 132 |