Conditions | 12 |
Paths | 18 |
Total Lines | 35 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
49 | private static function checkOperation(JWK $key, string $usage): bool |
||
50 | { |
||
51 | $ops = $key->get('key_ops'); |
||
52 | if (!is_array($ops)) { |
||
53 | $ops = [$ops]; |
||
54 | } |
||
55 | switch ($usage) { |
||
56 | case 'verification': |
||
57 | if (!in_array('verify', $ops)) { |
||
58 | throw new \InvalidArgumentException('Key cannot be used to verify a signature'); |
||
59 | } |
||
60 | |||
61 | return true; |
||
62 | case 'signature': |
||
63 | if (!in_array('sign', $ops)) { |
||
64 | throw new \InvalidArgumentException('Key cannot be used to sign'); |
||
65 | } |
||
66 | |||
67 | return true; |
||
68 | case 'encryption': |
||
69 | if (!in_array('encrypt', $ops) && !in_array('wrapKey', $ops)) { |
||
70 | throw new \InvalidArgumentException('Key cannot be used to encrypt'); |
||
71 | } |
||
72 | |||
73 | return true; |
||
74 | case 'decryption': |
||
75 | if (!in_array('decrypt', $ops) && !in_array('unwrapKey', $ops)) { |
||
76 | throw new \InvalidArgumentException('Key cannot be used to decrypt'); |
||
77 | } |
||
78 | |||
79 | return true; |
||
80 | default: |
||
81 | throw new \InvalidArgumentException('Unsupported key usage.'); |
||
82 | } |
||
83 | } |
||
84 | |||
129 |