Conditions | 14 |
Paths | 10 |
Total Lines | 35 |
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 |
||
50 | private static function checkOperation(JWK $key, string $usage): void |
||
51 | { |
||
52 | $ops = $key->get('key_ops'); |
||
53 | if (!\is_array($ops)) { |
||
54 | throw new InvalidArgumentException('Invalid key parameter "key_ops". Should be a list of key operations'); |
||
55 | } |
||
56 | switch ($usage) { |
||
57 | case 'verification': |
||
58 | if (!\in_array('verify', $ops, true)) { |
||
59 | throw new InvalidArgumentException('Key cannot be used to verify a signature'); |
||
60 | } |
||
61 | |||
62 | break; |
||
63 | case 'signature': |
||
64 | if (!\in_array('sign', $ops, true)) { |
||
65 | throw new InvalidArgumentException('Key cannot be used to sign'); |
||
66 | } |
||
67 | |||
68 | break; |
||
69 | case 'encryption': |
||
70 | if (!\in_array('encrypt', $ops, true) && !\in_array('wrapKey', $ops, true) && !\in_array('deriveKey', $ops, true)) { |
||
71 | throw new InvalidArgumentException('Key cannot be used to encrypt'); |
||
72 | } |
||
73 | |||
74 | break; |
||
75 | case 'decryption': |
||
76 | if (!\in_array('decrypt', $ops, true) && !\in_array('unwrapKey', $ops, true) && !\in_array('deriveBits', $ops, true)) { |
||
77 | throw new InvalidArgumentException('Key cannot be used to decrypt'); |
||
78 | } |
||
79 | |||
80 | break; |
||
81 | default: |
||
82 | throw new InvalidArgumentException('Unsupported key usage.'); |
||
83 | } |
||
84 | } |
||
85 | |||
112 |