UuidGenerator   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRequestIdentifier() 0 10 1
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