Completed
Push — master ( 9e9693...9e4b3d )
by Emad
02:46
created

UUIDManager   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A generate() 0 20 1
1
<?php 
2
3
namespace Emadadly\LaravelUuid;
4
5
class UUIDManager
6
{
7
    /**
8
     * @type string
9
     */
10
    private $uuid;
11
12
    public function __construct()
13
    {
14
        $uuid = $this->generate();
15
16
        $this->uuid = $uuid;
17
18
        return $uuid;
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
19
    }
20
21
/*    public function __toString()
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
22
    {
23
        return $this->uuid;
24
    }*/
25
26
27
    /**
28
     *
29
     * This function will return a UUID
30
     *
31
     * @return type string
32
     */
33
    public static function generate()
34
    {
35
36
            mt_srand((double)microtime()*10000);
37
            $charid = strtoupper(md5(uniqid(rand(), true)));
38
            $hyphen = chr(45);// "-"
39
            $uuid = chr(123)// "{"
40
            .substr($charid, 0, 8).$hyphen
41
            .substr($charid, 8, 4).$hyphen
42
            .substr($charid,12, 4).$hyphen
43
            .substr($charid,16, 4).$hyphen
44
            .substr($charid,20,12)
45
            .chr(125);// "}"
46
47
            $uuid = str_replace('{', '' , $uuid);
48
            $uuid = str_replace('}', '' , $uuid);
49
50
            return $uuid;
51
    
52
    }
53
}