DomainId::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Nord\Lumen\Core\Domain;
4
5
use Crisu83\ShortId\ShortId;
6
use Nord\Lumen\Core\Contracts\ValueObject;
7
8
class DomainId implements ValueObject
9
{
10
    /**
11
     * @var string
12
     */
13
    private $value;
14
15
    /**
16
     * @var \Crisu83\ShortId\ShortId
17
     */
18
    private static $identityGenerator;
19
20
    /**
21
     * DomainId constructor.
22
     *
23
     * @param string $value
24
     */
25
    public function __construct($value = null)
26
    {
27
        $this->value = $value === null ? $this->nextIdentity() : $value;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    private static function nextIdentity()
34
    {
35
        if (self::$identityGenerator === null) {
36
            self::$identityGenerator = ShortId::create();
37
        }
38
39
        return self::$identityGenerator->generate();
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getValue()
46
    {
47
        return $this->value;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function __toString()
54
    {
55
        return $this->getValue();
56
    }
57
}
58