Completed
Push — Lonja/albertc ( 7a2bf6 )
by Albert
20:41 queued 16:20
created

AggregateRootId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 25
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A instance() 0 4 1
A instanceFromId() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kata\Domain\Common\ValueObject;
6
7
use Ramsey\Uuid\Uuid;
8
9
abstract class AggregateRootId
10
{
11
    /** @var string */
12
    protected $uuid;
13
14
    public function __construct(string $id = null)
15
    {
16
        $this->uuid = $id ?: Uuid::uuid4()->toString();
17
    }
18
19
    public static function instance(): AggregateRootId
20
    {
21
        return new static();
22
    }
23
24
    public static function instanceFromId(string $id): AggregateRootId
25
    {
26
        return new static($id);
27
    }
28
29
    public function __toString(): string
30
    {
31
        return (string) $this->uuid;
32
    }
33
}
34