DomainId   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 50
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A nextIdentity() 0 8 2
A getValue() 0 4 1
A __toString() 0 4 1
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