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 |
||
76 | public function unserialize(string $input): JWE |
||
77 | { |
||
78 | $data = json_decode($input, true); |
||
79 | if (!is_array($data) || !array_key_exists('ciphertext', $data) || !array_key_exists('recipients', $data)) { |
||
80 | throw new \InvalidArgumentException('Unsupported input.'); |
||
81 | } |
||
82 | |||
83 | $ciphertext = Base64Url::decode($data['ciphertext']); |
||
84 | $iv = Base64Url::decode($data['iv']); |
||
85 | $tag = Base64Url::decode($data['tag']); |
||
86 | $aad = array_key_exists('aad', $data) ? Base64Url::decode($data['aad']) : null; |
||
87 | $encodedSharedProtectedHeader = array_key_exists('protected', $data) ? $data['protected'] : null; |
||
88 | $sharedProtectedHeader = $encodedSharedProtectedHeader ? json_decode(Base64Url::decode($encodedSharedProtectedHeader), true) : []; |
||
89 | $sharedHeader = array_key_exists('unprotected', $data) ? $data['unprotected'] : []; |
||
90 | $recipients = []; |
||
91 | foreach ($data['recipients'] as $recipient) { |
||
92 | $encryptedKey = array_key_exists('encrypted_key', $recipient) ? Base64Url::decode($recipient['encrypted_key']) : null; |
||
93 | $header = array_key_exists('header', $recipient) ? $recipient['header'] : []; |
||
94 | $recipients[] = Recipient::create($header, $encryptedKey); |
||
95 | } |
||
96 | |||
97 | return JWE::create( |
||
98 | $ciphertext, |
||
99 | $iv, |
||
100 | $tag, |
||
101 | $aad, |
||
102 | $sharedHeader, |
||
103 | $sharedProtectedHeader, |
||
104 | $encodedSharedProtectedHeader, |
||
105 | $recipients); |
||
106 | } |
||
107 | } |
||
108 |