Completed
Push — master ( c41f12...847679 )
by Vadim
01:45 queued 10s
created

Xhgui_Util::replaceDots()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
class Xhgui_Util
4
{
5
    const KEY_DELIMITER = '__';
6
7
    /**
8
     * Creates a simplified URL given a standard URL.
9
     * Does the following transformations:
10
     *
11
     * - Remove numeric values after =.
12
     *
13
     * @param string $url
14
     * @return string
15
     */
16
    public static function simpleUrl($url)
17
    {
18
        $callable = Xhgui_Config::read('profiler.simple_url');
19
        if (is_callable($callable)) {
20
            return call_user_func($callable, $url);
21
        }
22
        return preg_replace('/\=\d+/', '', $url);
23
    }
24
25
    public static function replaceDots(array $profile): array
26
    {
27
        $result = [];
28
        foreach ($profile as $key => $value) {
29
            $key = preg_replace('/\./', static::KEY_DELIMITER, $key);
30
            $result[$key] = $value;
31
        }
32
33
        return $result;
34
    }
35
36
    /**
37
     * Returns an new ObjectId-like string, where its first 8
38
     * characters encode the current unix timestamp and the
39
     * next 16 are random.
40
     *
41
     * @see http://php.net/manual/en/mongodb-bson-objectid.construct.php
42
     *
43
     * @return string
44
     */
45
    public static function generateId()
46
    {
47
        return dechex(time()) . bin2hex(random_bytes(8));
48
    }
49
50
}
51