| Conditions | 22 |
| Paths | 20 |
| Total Lines | 58 |
| Code Lines | 39 |
| 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 |
||
| 26 | private function checkKeyUsage(JWKInterface $key, $usage) |
||
| 27 | { |
||
| 28 | if (!$key->has('use') && !$key->has('key_ops')) { |
||
| 29 | return true; |
||
| 30 | } |
||
| 31 | if ($key->has('use')) { |
||
| 32 | $use = $key->get('use'); |
||
| 33 | switch ($usage) { |
||
| 34 | case 'verification': |
||
| 35 | case 'signature': |
||
| 36 | if ('sig' === $use) { |
||
| 37 | return true; |
||
| 38 | } |
||
| 39 | |||
| 40 | return false; |
||
| 41 | case 'encryption': |
||
| 42 | case 'decryption': |
||
| 43 | if ('enc' === $use) { |
||
| 44 | return true; |
||
| 45 | } |
||
| 46 | |||
| 47 | return false; |
||
| 48 | default: |
||
| 49 | throw new \InvalidArgumentException('Unsupported key usage.'); |
||
| 50 | } |
||
| 51 | } elseif ($key->has('key_ops') && is_array($ops = $key->get('key_ops'))) { |
||
| 52 | switch ($usage) { |
||
| 53 | case 'verification': |
||
| 54 | if (in_array('verify', $ops)) { |
||
| 55 | return true; |
||
| 56 | } |
||
| 57 | |||
| 58 | return false; |
||
| 59 | case 'signature': |
||
| 60 | if (in_array('sign', $ops)) { |
||
| 61 | return true; |
||
| 62 | } |
||
| 63 | |||
| 64 | return false; |
||
| 65 | case 'encryption': |
||
| 66 | if (in_array('encrypt', $ops) || in_array('wrapKey', $ops)) { |
||
| 67 | return true; |
||
| 68 | } |
||
| 69 | |||
| 70 | return false; |
||
| 71 | case 'decryption': |
||
| 72 | if (in_array('decrypt', $ops) || in_array('unwrapKey', $ops)) { |
||
| 73 | return true; |
||
| 74 | } |
||
| 75 | |||
| 76 | return false; |
||
| 77 | default: |
||
| 78 | throw new \InvalidArgumentException('Unsupported key usage.'); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return true; |
||
| 83 | } |
||
| 84 | |||
| 100 |