UUID   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 1
eloc 7
c 2
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A v4() 0 9 1
1
<?php
2
3
namespace Vectorface\UUID;
4
5
class UUID
6
{
7
    /**
8
     * Generate a random universally unique identifier; a UUIDv4
9
     *
10
     * @return string A UUID, This should look something like c2b134ae-04a4-4e82-89e0-51cbe9639dfb
11
     */
12 1
    public static function v4()
13
    {
14 1
        $uuidStr = random_bytes(16); // 128 bits
15 1
        $uuidStr[6] = chr(0x40 | (ord($uuidStr[6]) & 0x0f)); // Set the high nibble of the 7th byte to 4
16 1
        $uuidStr[8] = chr(0x80 | (ord($uuidStr[8]) & 0x3f)); // Set highest two bits of the 9th byte to 0b10
17
18 1
        return sprintf(
19 1
            "%s%s-%s-%s-%s-%s%s%s",
20 1
            ...str_split(bin2hex($uuidStr), 4)
21
        );
22
    }
23
}
24
25