Conditions | 7 |
Paths | 8 |
Total Lines | 13 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 7 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
37 | 62 | public function normalize($key): string |
|
38 | { |
||
39 | 62 | if (is_string($key) || is_int($key)) { |
|
40 | 43 | $key = (string) $key; |
|
41 | 43 | $length = mb_strlen($key, '8bit'); |
|
42 | 43 | return (strpbrk($key, '{}()/\@:') || $length < 1 || $length > 64) ? md5($key) : $key; |
|
43 | } |
||
44 | |||
45 | 19 | if (($key = json_encode($key)) === false) { |
|
46 | 3 | throw new InvalidArgumentException('Invalid key. ' . json_last_error_msg()); |
|
47 | } |
||
48 | |||
49 | 16 | return md5($key); |
|
50 | } |
||
52 |