UuidIdentifier::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * This file is part of the Borobudur-Cqrs package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
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 Borobudur\Cqrs;
12
13
use Rhumsaa\Uuid\Uuid;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     8/18/15
18
 */
19
class UuidIdentifier implements IdentifierInterface
20
{
21
    /**
22
     * @var Uuid
23
     */
24
    protected $value;
25
26
    /**
27
     * Constructor.
28
     *
29
     * @param Uuid $uuid
30
     */
31
    public function __construct(Uuid $uuid)
32
    {
33
        $this->value = $uuid;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public static function generate()
40
    {
41
        return new static(Uuid::uuid4());
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     *
47
     * @return static
48
     */
49
    public static function fromString($id)
50
    {
51
        if (null === $id) {
52
            return null;
53
        }
54
55
        return new static(Uuid::fromString($id));
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function equals(IdentifierInterface $identifier)
62
    {
63
        return $this->toString() === $identifier->toString();
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function toString()
70
    {
71
        return (string) $this->value;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function __toString()
78
    {
79
        return $this->toString();
80
    }
81
}
82