Passed
Push — master ( 819f30...8ceff2 )
by Thorsten
02:22
created

Uuid::makeEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Daikon\Entity\ValueObject;
4
5
use Daikon\Entity\Assert\Assertion;
6
use Ramsey\Uuid\Uuid as RamseyUuid;
7
8
final class Uuid implements ValueObjectInterface
9
{
10
    /**
11
     * @var null
12
     */
13
    private const NIL = null;
14
15
    /**
16
     * @var RamseyUuid|null
17
     */
18
    private $value;
19
20 1
    public static function generate(): self
21
    {
22 1
        return new self(RamseyUuid::uuid4());
23
    }
24
25
    /**
26
     * @param string|null $nativeValue
27
     * @return self
28
     */
29 17
    public static function fromNative($nativeValue): self
30
    {
31 17
        Assertion::nullOrString($nativeValue);
32 17
        return empty($nativeValue) ? new self : new self(RamseyUuid::fromString($nativeValue));
33
    }
34
35 3
    public function equals(ValueObjectInterface $otherValue): bool
36
    {
37 3
        return $otherValue instanceof self && $this->toNative() === $otherValue->toNative();
38
    }
39
40 7
    public function toNative(): ?string
41
    {
42 7
        return $this->value ? $this->value->toString() : $this->value;
43
    }
44
45 1
    public function __toString(): string
46
    {
47 1
        return $this->value ? $this->value->toString() : "null";
48
    }
49
50 17
    private function __construct(RamseyUuid $value = null)
51
    {
52 17
        $this->value = $value;
53 17
    }
54
}
55