Completed
Push — master ( b2cd25...08acda )
by Paweł
26s queued 10s
created

StringGenerator::random()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Generator;
6
7
use Exception;
8
9
final class StringGenerator implements StringGeneratorInterface
10
{
11
    /**
12
     * @throws Exception
13
     */
14
    public static function random(int $length): string
15
    {
16
        $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
17
18
        $str = '';
19
        $max = mb_strlen($keyspace, '8bit') - 1;
20
        for ($i = 0; $i < $length; ++$i) {
21
            $str .= $keyspace[random_int(0, $max)];
22
        }
23
24
        return $str;
25
    }
26
}
27