Util::generateId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
    public static function generateId(): string
20
    {
21
        return dechex(time()) . bin2hex(random_bytes(8));
22
    }
23
}
24