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

AggregateRootId::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 1
crap 6
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