UuidGenerator::getRequestIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 2
1
<?php
2
3
namespace ScayTrase\Api\IdGenerator;
4
5
use ScayTrase\Api\Rpc\RpcRequestInterface;
6
7
/**
8
 * Class UuidGenerator
9
 * @link http://stackoverflow.com/a/15875555/1361089
10
 */
11
final class UuidGenerator implements IdGeneratorInterface
12
{
13
    /**
14
     * @param RpcRequestInterface|null $request
15
     * @return string
16
     */
17
    public function getRequestIdentifier(RpcRequestInterface $request = null)
18
    {
19
        /** @var string $data */
20
        $data = random_bytes(16);
21
22
        $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
23
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
24
25
        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
26
    }
27
}
28