| Conditions | 15 | 
| Paths | 239 | 
| Total Lines | 47 | 
| Code Lines | 33 | 
| 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 | ||
| 96 | public function unserialize(string $input): JWS | ||
| 97 |     { | ||
| 98 | $data = $this->jsonConverter->decode($input); | ||
| 99 |         if (!is_array($data) || !array_key_exists('signatures', $data)) { | ||
| 100 |             throw new \InvalidArgumentException('Unsupported input.'); | ||
| 101 | } | ||
| 102 | |||
| 103 | $isPayloadEncoded = null; | ||
| 104 |         $rawPayload = array_key_exists('payload', $data) ? $data['payload'] : null; | ||
| 105 | $signatures = []; | ||
| 106 |         foreach ($data['signatures'] as $signature) { | ||
| 107 |             if (!is_array($signature) || !array_key_exists('signature', $signature)) { | ||
| 108 |                 throw new \InvalidArgumentException('Unsupported input.'); | ||
| 109 | } | ||
| 110 |             $encodedProtectedHeaders = array_key_exists('protected', $signature) ? $signature['protected'] : null; | ||
| 111 | $protectedHeaders = null !== $encodedProtectedHeaders ? $this->jsonConverter->decode(Base64Url::decode($encodedProtectedHeaders)) : []; | ||
| 112 | $signatures[] = [ | ||
| 113 | 'signature' => Base64Url::decode($signature['signature']), | ||
| 114 | 'protected' => $protectedHeaders, | ||
| 115 | 'encoded_protected' => $encodedProtectedHeaders, | ||
| 116 |                 'header' => array_key_exists('header', $signature) ? $signature['header'] : [], | ||
| 117 | ]; | ||
| 118 |             if (null === $isPayloadEncoded) { | ||
| 119 | $isPayloadEncoded = self::isPayloadEncoded($protectedHeaders); | ||
| 120 | } | ||
| 121 |             if ($this->isPayloadEncoded($protectedHeaders) !== $isPayloadEncoded) { | ||
| 122 |                 throw new \InvalidArgumentException('Foreign payload encoding detected.'); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 |         if (null === $rawPayload) { | ||
| 127 | $payload = null; | ||
| 128 |         } else { | ||
| 129 | $payload = false === $isPayloadEncoded ? $rawPayload : Base64Url::decode($rawPayload); | ||
| 130 | } | ||
| 131 | $jws = JWS::create($payload, $rawPayload); | ||
| 132 |         foreach ($signatures as $signature) { | ||
| 133 | $jws = $jws->addSignature( | ||
| 134 | $signature['signature'], | ||
| 135 | $signature['protected'], | ||
| 136 | $signature['encoded_protected'], | ||
| 137 | $signature['header'] | ||
| 138 | ); | ||
| 139 | } | ||
| 140 | |||
| 141 | return $jws; | ||
| 142 | } | ||
| 143 | |||
| 165 |