Completed
Pull Request — master (#2)
by Sujip
14:35
created

Uuid::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
namespace Omnipay\ZipPay\Helper;
3
4
abstract class Uuid
5
{
6
7
    /**
8
     * Create UUID v4 string
9
     *
10
     * Inspiration from GUI: the guid generator
11
     * @see http://guid.us/GUID/PHP
12
     *
13
     * @return string UUID v4 as string
14
     */
15
    public static function create()
16
    {
17
        // use COM helper if available
18
        if (function_exists('com_create_guid')) {
19
            return com_create_guid();
20
        }
21
22
        // generate UUID
23
        mt_srand((double) microtime() * 10000); // optional for php 4.2.0 and up.
24
        $charid = strtoupper(md5(uniqid(rand(), true)));
25
        $uuid = join('-', array(
26
            substr($charid, 0, 8),
27
            substr($charid, 8, 4),
28
            substr($charid, 12, 4),
29
            substr($charid, 16, 4),
30
            substr($charid, 20, 12),
31
        ));
32
33
        return $uuid;
34
    }
35
36
    /**
37
     * Create a UUID v4 string enclosed by braces
38
     * @return string UUID v4 string with braces
39
     */
40
    public static function createEnclosed()
41
    {
42
        return '{' . self::create() . '}';
43
    }
44
}
45