| Conditions | 11 |
| Paths | 33 |
| Total Lines | 38 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | 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 |
||
| 70 | public function verify(JWSInterface $jws, JWKSetInterface $jwk_set = null, $detached_payload = null) |
||
| 71 | { |
||
| 72 | if (null !== $detached_payload && !empty($jws->getPayload())) { |
||
| 73 | throw new \InvalidArgumentException('A detached payload is set, but the JWS already has a payload'); |
||
| 74 | } |
||
| 75 | $complete_header = $jws->getHeaders(); |
||
| 76 | if (null === $jwk_set) { |
||
| 77 | $jwk_set = $this->getKeysFromCompleteHeader( |
||
| 78 | $complete_header, |
||
| 79 | JWKFinderManagerInterface::KEY_TYPE_PUBLIC | JWKFinderManagerInterface::KEY_TYPE_SYMMETRIC | JWKFinderManagerInterface::KEY_TYPE_NONE |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | |||
| 83 | $input = $jws->getEncodedProtectedHeaders().'.'.(null === $detached_payload ? $jws->getEncodedPayload() : $detached_payload); |
||
| 84 | |||
| 85 | if (0 === count($jwk_set)) { |
||
| 86 | return false; |
||
| 87 | } |
||
| 88 | foreach ($jwk_set->getKeys() as $jwk) { |
||
| 89 | $algorithm = $this->getAlgorithm($complete_header, $jwk); |
||
| 90 | if (!$this->checkKeyUsage($jwk, 'verification')) { |
||
| 91 | continue; |
||
| 92 | } |
||
| 93 | if (!$this->checkKeyAlgorithm($jwk, $algorithm->getAlgorithmName())) { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | try { |
||
| 97 | if (true === $algorithm->verify($jwk, $input, $jws->getSignature())) { |
||
| 98 | $this->getCheckerManager()->checkJWT($jws); |
||
| 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 | |||
| 149 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.