| Conditions | 10 |
| Paths | 15 |
| Total Lines | 34 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 4 | 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 |
||
| 50 | * |
||
| 51 | * @throws \InvalidArgumentException |
||
| 52 | */ |
||
| 53 | public function verifyWithKey(JWSInterface $jws, JWKInterface $jwk, $detached_payload = null) |
||
| 54 | { |
||
| 55 | $jwk_set = new JWKSet(); |
||
| 56 | $jwk_set = $jwk_set->addKey($jwk); |
||
| 57 | |||
| 58 | return $this->verifyWithKeySet($jws, $jwk_set, $detached_payload); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * {@inheritdoc} |
||
| 63 | * |
||
| 64 | * @throws \InvalidArgumentException |
||
| 65 | */ |
||
| 66 | public function verifyWithKeySet(JWSInterface $jws, JWKSetInterface $jwk_set, $detached_payload = null) |
||
| 67 | { |
||
| 68 | $this->checkPayload($jws, $detached_payload); |
||
| 69 | $this->checkJWKSet($jwk_set); |
||
| 70 | $this->checkSignaturess($jws); |
||
| 71 | |||
| 72 | $nb_signatures = $jws->countSignatures(); |
||
| 73 | |||
| 74 | for ($i = 0; $i < $nb_signatures; $i++) { |
||
| 75 | $signature = $jws->getSignature($i); |
||
| 76 | $input = $signature->getEncodedProtectedHeaders().'.'.(null === $detached_payload ? $jws->getEncodedPayload() : $detached_payload); |
||
| 77 | |||
| 78 | foreach ($jwk_set->getKeys() as $jwk) { |
||
| 79 | $algorithm = $this->getAlgorithm($signature); |
||
| 80 | try { |
||
| 81 | $this->checkKeyUsage($jwk, 'verification'); |
||
| 82 | $this->checkKeyAlgorithm($jwk, $algorithm->getAlgorithmName()); |
||
| 83 | if (true === $algorithm->verify($jwk, $input, $signature->getSignature())) { |
||
| 84 | $this->getCheckerManager()->checkJWT($jws); |
||
| 152 |