| Conditions | 10 |
| Paths | 17 |
| Total Lines | 31 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 62 | public function verify(JWSInterface $jws, JWKSetInterface $jwk_set, $detached_payload = null) |
||
| 63 | { |
||
| 64 | if (null !== $detached_payload && !empty($jws->getPayload())) { |
||
| 65 | throw new \InvalidArgumentException('A detached payload is set, but the JWS already has a payload'); |
||
| 66 | } |
||
| 67 | $input = $jws->getEncodedProtectedHeaders().'.'.(null === $detached_payload ? $jws->getEncodedPayload() : $detached_payload); |
||
| 68 | |||
| 69 | if (0 === count($jwk_set)) { |
||
| 70 | return false; |
||
| 71 | } |
||
| 72 | foreach ($jwk_set->getKeys() as $jwk) { |
||
| 73 | $algorithm = $this->getAlgorithm($jws->getHeaders()); |
||
| 74 | if (!$this->checkKeyUsage($jwk, 'verification')) { |
||
| 75 | continue; |
||
| 76 | } |
||
| 77 | if (!$this->checkKeyAlgorithm($jwk, $algorithm->getAlgorithmName())) { |
||
| 78 | continue; |
||
| 79 | } |
||
| 80 | try { |
||
| 81 | if (true === $algorithm->verify($jwk, $input, $jws->getSignature())) { |
||
| 82 | $this->getCheckerManager()->checkJWT($jws); |
||
| 83 | |||
| 84 | return true; |
||
| 85 | } |
||
| 86 | } catch (\Exception $e) { |
||
| 87 | //We do nothing, we continue with other keys |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return false; |
||
| 92 | } |
||
| 93 | |||
| 114 |