Completed
Push — master ( df309f...9e12f0 )
by Rafael
08:32
created

Uuid   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 26
c 0
b 0
f 0
ccs 11
cts 11
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A createFromData() 0 16 3
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Util;
12
13
class Uuid
14
{
15
    /**
16
     * Create universal identifier for given data.
17
     * Helpful to create unique across then system, but the same when use the same data
18
     *
19
     * @param mixed $data
20
     *
21
     * @return string
22
     */
23 1
    public static function createFromData($data)
24
    {
25 1
        if (\is_array($data) || \is_object($data)) {
26 1
            $data = serialize($data);
27
        }
28
29 1
        $hash = strtoupper(md5($data));
30
31 1
        return implode(
32 1
            '-',
33
            [
34 1
                substr($hash, 0, 8),
35 1
                substr($hash, 8, 4),
36 1
                substr($hash, 12, 4),
37 1
                substr($hash, 16, 4),
38 1
                substr($hash, 20, 8),
39
            ]
40
        );
41
    }
42
}
43