Passed
Push — master ( 9e2434...486cd6 )
by Ron
01:59
created

MySQLUUIDGenerator   A

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