Issues (5)

src/functions.php (1 issue)

Labels
Severity
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
It seems like $keyspace can also be of type null; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
    $keysize = strlen(/** @scrutinizer ignore-type */ $keyspace) - 1;
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