MySQLUUIDGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 13
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A genUUIDv4() 0 16 2
1
<?php
2
3
namespace Kir\MySQL\Databases\MySQL;
4
5
use RuntimeException;
6
use Throwable;
7
8
class MySQLUUIDGenerator {
9
	/**
10
	 * @return string
11
	 */
12
	public static function genUUIDv4(): string {
13
		// Generate a unique id from a former random-uuid-generator
14
		try {
15
			return sprintf('ID%04x%04x%04x%04x%04x%04x%04x%04x',
16
				random_int(0, 0xffff),
17
				random_int(0, 0xffff),
18
				random_int(0, 0xffff),
19
				random_int(0, 0x0fff) | 0x4000,
20
				random_int(0, 0x3fff) | 0x8000,
21
				random_int(0, 0xffff),
22
				random_int(0, 0xffff),
23
				random_int(0, 0xffff)
24
			);
25
		} catch(Throwable $e) {
26
			// Should not throw an excepion under normal conditions
27
			throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
28
		}
29
	}
30
}
31