| Conditions | 11 |
| Paths | 15 |
| Total Lines | 33 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 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 |
||
| 66 | public function verifyWithKeySet(JWSInterface $jws, JWKSetInterface $jwk_set, $detached_payload = null) |
||
| 67 | { |
||
| 68 | if (null !== $detached_payload && !empty($jws->getEncodedPayload())) { |
||
| 69 | throw new \InvalidArgumentException('A detached payload is set, but the JWS already has a payload.'); |
||
| 70 | } |
||
| 71 | if (0 === count($jwk_set)) { |
||
| 72 | throw new \InvalidArgumentException('No key in the key set.'); |
||
| 73 | } |
||
| 74 | foreach ($jws->getSignatures() as $signature) { |
||
| 75 | $input = $signature->getEncodedProtectedHeaders().'.'.(null === $detached_payload ? $jws->getEncodedPayload() : $detached_payload); |
||
| 76 | |||
| 77 | foreach ($jwk_set->getKeys() as $jwk) { |
||
| 78 | $algorithm = $this->getAlgorithm($signature); |
||
| 79 | if (!$this->checkKeyUsage($jwk, 'verification')) { |
||
| 80 | continue; |
||
| 81 | } |
||
| 82 | if (!$this->checkKeyAlgorithm($jwk, $algorithm->getAlgorithmName())) { |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | try { |
||
| 86 | if (true === $algorithm->verify($jwk, $input, $signature->getSignature())) { |
||
| 87 | return true; |
||
| 88 | } |
||
| 89 | } catch (\Exception $e) { |
||
| 90 | //We do nothing, we continue with other keys |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | |||
| 97 | return false; |
||
| 98 | } |
||
| 99 | |||
| 123 |