| Conditions | 10 |
| Paths | 65 |
| Total Lines | 27 |
| Code Lines | 22 |
| 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 |
||
| 95 | public function unserialize(string $input): JWE |
||
| 96 | { |
||
| 97 | $data = $this->jsonConverter->decode($input); |
||
| 98 | if (!is_array($data) || !array_key_exists('ciphertext', $data) || array_key_exists('recipients', $data)) { |
||
| 99 | throw new \InvalidArgumentException('Unsupported input.'); |
||
| 100 | } |
||
| 101 | |||
| 102 | $ciphertext = Base64Url::decode($data['ciphertext']); |
||
| 103 | $iv = Base64Url::decode($data['iv']); |
||
| 104 | $tag = Base64Url::decode($data['tag']); |
||
| 105 | $aad = array_key_exists('aad', $data) ? Base64Url::decode($data['aad']) : null; |
||
| 106 | $encodedSharedProtectedHeader = array_key_exists('protected', $data) ? $data['protected'] : null; |
||
| 107 | $sharedProtectedHeader = $encodedSharedProtectedHeader ? $this->jsonConverter->decode(Base64Url::decode($encodedSharedProtectedHeader)) : []; |
||
| 108 | $sharedHeader = array_key_exists('unprotected', $data) ? $data['unprotected'] : []; |
||
| 109 | $encryptedKey = array_key_exists('encrypted_key', $data) ? Base64Url::decode($data['encrypted_key']) : null; |
||
| 110 | $header = array_key_exists('header', $data) ? $data['header'] : []; |
||
| 111 | |||
| 112 | return JWE::create( |
||
| 113 | $ciphertext, |
||
| 114 | $iv, |
||
| 115 | $tag, |
||
| 116 | $aad, |
||
| 117 | $sharedHeader, |
||
| 118 | $sharedProtectedHeader, |
||
| 119 | $encodedSharedProtectedHeader, |
||
| 120 | [Recipient::create($header, $encryptedKey)]); |
||
| 121 | } |
||
| 122 | } |
||
| 123 |