HashGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 17
c 0
b 0
f 0
rs 10
ccs 7
cts 7
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 13 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