Completed
Pull Request — master (#44)
by
unknown
02:51
created

Uuid::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the xAPI package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\XApi\Model;
13
14
use Ramsey\Uuid\Uuid as RamseyUuid;
15
use Rhumsaa\Uuid\Uuid as RhumsaaUuid;
16
17
/**
18
 * @author Jérôme Parmentier <[email protected]>
19
 */
20
final class Uuid
21
{
22
    /**
23
     * @var RamseyUuid|RhumsaaUuid;
24
     */
25
    private $uuid;
26
27
    private function __construct($uuid)
28
    {
29
        $this->uuid = $uuid;
30
    }
31
32
    /**
33
     * @param string $uuid
34
     * @return Uuid
35
     */
36
    public static function fromString($uuid)
37
    {
38
        if (class_exists('Rhumsaa\Uuid\Uuid')) {
39
            return new self(RhumsaaUuid::fromString($uuid));
40
        }
41
42
        return new self(RamseyUuid::fromString($uuid));
43
    }
44
45
    public function toString()
46
    {
47
        return $this->uuid->toString();
48
    }
49
50
    public function equals(Uuid $uuid)
51
    {
52
        return $this->uuid->toString() === $uuid->toString();
53
    }
54
}
55