mkorkmaz /
redislabs-redisgraph-php
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Redislabs\Module\RedisGraph; |
||
| 6 | |||
| 7 | use function random_int; |
||
| 8 | |||
| 9 | function quotedString(string $str): string |
||
| 10 | { |
||
| 11 | return '"' . $str . '"'; |
||
| 12 | } |
||
| 13 | |||
| 14 | /* |
||
| 15 | * We have to be sure that random string is statistically unique. |
||
| 16 | */ |
||
| 17 | |||
| 18 | function randomString( |
||
| 19 | ?int $length = 10, |
||
| 20 | ?string $keyspace = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
||
| 21 | ): string { |
||
| 22 | $str = ''; |
||
| 23 | $keysize = strlen($keyspace) - 1; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 24 | for ($i = 0; $i < $length; ++$i) { |
||
| 25 | $randomKeyPosition = random_int(0, $keysize); |
||
| 26 | $str .= $keyspace[$randomKeyPosition]; |
||
| 27 | } |
||
| 28 | return $str; |
||
| 29 | } |
||
| 30 |