Conditions | 2 |
Paths | 2 |
Total Lines | 10 |
Code Lines | 4 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 2.032 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
42 | 34 | public static function randomBytes(int $length): string |
|
43 | { |
||
44 | // Get $length cryptographically secure pseudo-random bytes |
||
45 | 34 | $rnd=\random_bytes($length); |
|
46 | |||
47 | 34 | if (strlen($rnd) !== $length) { |
|
48 | throw new Exception("random_bytes did not return the requested number of bytes"); |
||
49 | } |
||
50 | |||
51 | 34 | return $rnd; |
|
52 | } |
||
54 | } |