Completed
Pull Request — master (#331)
by Elan
01:21
created

Xhgui_Util   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 21
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace XHGui;
4
5
class Util
6
{
7
    /**
8
     * Returns an new ObjectId-like string, where its first 8
9
     * characters encode the current unix timestamp and the
10
     * next 16 are random.
11
     *
12
     * The length will always be 24 bytes.
13
     * NOTE: The above assumption will fail as the date value will overflow
14
     * past Feb 7 06:28:15 2106 UTC and Jan 19 03:14:07 2038 UTC on 32bit
15
     * systems
16
     *
17
     * @see https://php.net/manual/en/mongodb-bson-objectid.construct.php
18
     *
19
     * @return string
20
     */
21
    public static function generateId(): string
22
    {
23
        return dechex(time()) . bin2hex(random_bytes(8));
24
    }
25
}
26