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

MySQLUUIDGenerator::genUUIDv4()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 16
rs 9.8666
cc 2
nc 2
nop 0
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