HashGenerator::generate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
ccs 7
cts 7
cp 1
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Service;
4
5
/**
6
 * @author Vehsamrak
7
 */
8
class HashGenerator
9
{
10
11 10
    public static function generate(int $length = 8): string
12
    {
13 10
        $chunksNumber = ceil($length / 4);
14
15 10
        $hashString = '';
16
17 10
        while ($chunksNumber > 0) {
18 10
            $chunksNumber--;
19 10
            $hashString = sprintf('%s%04x', $hashString, mt_rand(0, 0xffff));
20
        }
21
22 10
        return substr($hashString, 0, $length);
23
    }
24
}
25