Completed
Push — master ( c2c97b...62409a )
by Frank
9s
created

UuidAggregateRootId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0
ccs 11
cts 11
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toString() 0 4 1
A toUuid() 0 4 1
A create() 0 4 1
A fromString() 0 4 1
1
<?php
2
3
namespace EventSauce\EventSourcing;
4
5
use Ramsey\Uuid\Uuid;
6
use Ramsey\Uuid\UuidInterface;
7
8
final class UuidAggregateRootId implements AggregateRootId
9
{
10
    /**
11
     * @var string
12
     */
13
    private $identifier;
14
15 5
    public function __construct(string $identifier)
16
    {
17 5
        $this->identifier = $identifier;
18 5
    }
19
20 4
    public function toString(): string
21
    {
22 4
        return $this->identifier;
23
    }
24
25 1
    public function toUuid(): UuidInterface
26
    {
27 1
        return Uuid::fromString($this->identifier);
28
    }
29
30 4
    public static function create(): UuidAggregateRootId
31
    {
32 4
        return new UuidAggregateRootId(Uuid::uuid4()->toString());
33
    }
34
35
    /**
36
     * @param string $aggregateRootId
37
     * @return static
38
     */
39 1
    public static function fromString(string $aggregateRootId): AggregateRootId
40
    {
41 1
        return new static($aggregateRootId);
42
    }
43
}