Completed
Push — master ( 23d8bc...a157cc )
by Frank
13s
created

UuidAggregateRootId   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0
ccs 14
cts 14
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A equals() 0 5 2
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 2
    public function equals($otherId): bool
21
    {
22 2
        return $otherId instanceof UuidAggregateRootId
23 2
            && $this->toUuid()->equals($otherId->toUuid());
24
    }
25
26 1
    public function toString(): string
27
    {
28 1
        return $this->identifier;
29
    }
30
31 3
    public function toUuid(): UuidInterface
32
    {
33 3
        return Uuid::fromString($this->identifier);
34
    }
35
36 4
    public static function create(): UuidAggregateRootId
37
    {
38 4
        return new UuidAggregateRootId(Uuid::uuid4()->toString());
39
    }
40
41
    /**
42
     * @param string $aggregateRootId
43
     * @return static
44
     */
45 1
    public static function fromString(string $aggregateRootId): AggregateRootId
46
    {
47 1
        return new static($aggregateRootId);
48
    }
49
}