V4GuidGenerator::newGuid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2.0017

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 15
ccs 12
cts 13
cp 0.9231
crap 2.0017
rs 9.8666
1
<?php
2
3
namespace Wikibase\DataModel\Services\Statement;
4
5
/**
6
 * Globally Unique Identifier generator.
7
 *
8
 * @since 1.0
9
 *
10
 * @license GPL-2.0-or-later
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class V4GuidGenerator {
14
15
	/**
16
	 * Generates and returns a GUID.
17
	 * @see http://php.net/manual/en/function.com-create-guid.php
18
	 * @see GuidGenerator::newGuid
19
	 *
20
	 * @since 1.0
21
	 *
22
	 * @return string
23
	 */
24 1
	public function newGuid() {
25 1
		if ( function_exists( 'com_create_guid' ) ) {
26
			return trim( com_create_guid(), '{}' );
27
		}
28
29 1
		return sprintf(
30 1
			'%04X%04X-%04X-%04X-%04X-%04X%04X%04X',
31 1
			mt_rand( 0, 65535 ),
32 1
			mt_rand( 0, 65535 ),
33 1
			mt_rand( 0, 65535 ),
34 1
			mt_rand( 16384, 20479 ),
35 1
			mt_rand( 32768, 49151 ),
36 1
			mt_rand( 0, 65535 ),
37 1
			mt_rand( 0, 65535 ),
38 1
			mt_rand( 0, 65535 )
39 1
		);
40
	}
41
42
}
43