Conditions | 6 |
Paths | 6 |
Total Lines | 12 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 6 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
29 | 12 | public function normalize($key): string |
|
30 | { |
||
31 | 12 | if (is_string($key) || is_int($key)) { |
|
32 | 3 | $key = (string) $key; |
|
33 | 3 | return ctype_alnum($key) && mb_strlen($key, '8bit') <= 32 ? $key : md5($key); |
|
34 | } |
||
35 | |||
36 | 9 | if (($key = json_encode($key)) === false) { |
|
37 | 1 | throw new InvalidArgumentException('Invalid key. ' . json_last_error_msg()); |
|
38 | } |
||
39 | |||
40 | 8 | return md5($key); |
|
41 | } |
||
43 |