| Conditions | 10 |
| Paths | 10 |
| Total Lines | 33 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 69 | public static function verify($token, $signature, $key, $algorithm = 'HS256') |
||
| 70 | { |
||
| 71 | $segments = explode('.', $token); |
||
| 72 | $segments = array_map('trim', $segments); |
||
| 73 | |||
| 74 | if (count($segments) == 3) { |
||
| 75 | array_pop($segments); |
||
| 76 | $data = implode('.', $segments); |
||
| 77 | |||
| 78 | if (Algorithm::validate($algorithm)) { |
||
| 79 | list($function, $algorithm) = Algorithm::map($algorithm); |
||
| 80 | |||
| 81 | switch ($function) { |
||
| 82 | case 'HMAC': |
||
| 83 | return Hmac::hash($algorithm, $data, $key, true) === $signature; |
||
| 84 | case 'hash_hmac': |
||
| 85 | return hash_hmac($algorithm, $data, $key, true) === $signature; |
||
| 86 | case 'openssl': |
||
| 87 | switch ($algorithm) { |
||
| 88 | case 'RS256': |
||
| 89 | return (bool)openssl_verify($data, $signature, $key, OPENSSL_ALGO_SHA1); |
||
| 90 | case 'RS256': |
||
| 91 | return (bool)openssl_verify($data, $signature, $key, OPENSSL_ALGO_SHA256); |
||
| 92 | case 'RS384': |
||
| 93 | return (bool)openssl_verify($data, $signature, $key, OPENSSL_ALGO_SHA384); |
||
| 94 | case 'RS512': |
||
| 95 | return (bool)openssl_verify($data, $signature, $key, OPENSSL_ALGO_SHA512); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return false; |
||
| 102 | } |
||
| 103 | } |