Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
Random | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
4.05 | |
0.00% |
0 / 1 |
string | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
int | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 |
1 | <?php |
2 | /** @noinspection PhpUnhandledExceptionInspection */ |
3 | declare(strict_types=1); |
4 | // TODO unit-test |
5 | |
6 | class Random { |
7 | public const charset_default = "abcdefghijklmnopqrstuvwxyz0123456789_-"; |
8 | |
9 | static function string(int $size, bool $cryptoSafe, string $charSet = self::charset_default): string { |
10 | $fileName = ''; |
11 | while ($size-- > 0) { |
12 | $fileName .= substr($charSet, self::int(0, strlen($charSet) - 1, $cryptoSafe), 1); |
13 | } |
14 | return $fileName; |
15 | } |
16 | |
17 | private static function int(int $min, int $max, bool $cryptoSafe): int { |
18 | if (!$cryptoSafe) { |
19 | return rand($min, $max); |
20 | } else { |
21 | return random_int($min, $max); |
22 | } |
23 | } |
24 | } |
25 | |
26 |