| Conditions | 11 |
| Paths | 29 |
| Total Lines | 37 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 71 | public function verifySignature(JWSInterface $jws, JWKSetInterface $jwk_set = null, $detached_payload = null) |
||
| 72 | { |
||
| 73 | if (null !== $detached_payload && !empty($jws->getPayload())) { |
||
| 74 | throw new \InvalidArgumentException('A detached payload is set, but the JWS already has a payload'); |
||
| 75 | } |
||
| 76 | $complete_header = $jws->getHeaders(); |
||
| 77 | if (null === $jwk_set) { |
||
| 78 | $jwk_set = $this->getKeysFromCompleteHeader( |
||
| 79 | $complete_header, |
||
| 80 | JWKFinderManagerInterface::KEY_TYPE_PUBLIC | JWKFinderManagerInterface::KEY_TYPE_SYMMETRIC | JWKFinderManagerInterface::KEY_TYPE_NONE |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | $input = $jws->getEncodedProtectedHeaders().'.'.(null === $detached_payload ? $jws->getEncodedPayload() : $detached_payload); |
||
| 85 | |||
| 86 | if (0 === count($jwk_set)) { |
||
| 87 | return false; |
||
| 88 | } |
||
| 89 | foreach ($jwk_set->getKeys() as $jwk) { |
||
| 90 | $algorithm = $this->getAlgorithm($complete_header, $jwk); |
||
| 91 | if (!$this->checkKeyUsage($jwk, 'verification')) { |
||
| 92 | continue; |
||
| 93 | } |
||
| 94 | if (!$this->checkKeyAlgorithm($jwk, $algorithm->getAlgorithmName())) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | try { |
||
| 98 | if (true === $algorithm->verify($jwk, $input, $jws->getSignature())) { |
||
| 99 | return true; |
||
| 100 | } |
||
| 101 | } catch (\InvalidArgumentException $e) { |
||
| 102 | //We do nothing, we continue with other keys |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return false; |
||
| 107 | } |
||
| 108 | |||
| 159 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.