Completed
Push — v3.2 ( 72f2ef...bca77e )
by Masiukevich
03:54
created

AggregateId   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 51
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A new() 0 4 1
A __toString() 0 3 1
A toString() 0 3 1
1
<?php
2
3
/**
4
 * Event Sourcing implementation.
5
 *
6
 * @author  Maksim Masiukevich <[email protected]>
7
 * @license MIT
8
 * @license https://opensource.org/licenses/MIT
9
 */
10
11
declare(strict_types = 1);
12
13
namespace ServiceBus\EventSourcing;
14
15
use function ServiceBus\Common\uuid;
16
use ServiceBus\EventSourcing\Exceptions\InvalidAggregateIdentifier;
17
18
/**
19
 * Base aggregate identifier class.
20
 */
21
abstract class AggregateId
22
{
23
    /**
24
     * Identifier.
25
     *
26
     * @var string
27
     */
28
    private $id;
29
30
    /**
31
     * @noinspection PhpDocMissingThrowsInspection
32
     *
33
     * @return static
34
     */
35 10
    public static function new(): self
36
    {
37
        /** @noinspection PhpUnhandledExceptionInspection */
38 10
        return new static(uuid());
39
    }
40
41
    /**
42
     * @param string $id
43
     *
44
     * @throws \ServiceBus\EventSourcing\Exceptions\InvalidAggregateIdentifier
45
     */
46 11
    final public function __construct(string $id)
47
    {
48 11
        if('' === $id)
49
        {
50 1
            throw InvalidAggregateIdentifier::emptyId();
51
        }
52
53 10
        $this->id = $id;
54 10
    }
55
56
    /**
57
     * @return string
58
     */
59 10
    public function toString(): string
60
    {
61 10
        return $this->id;
62
    }
63
64
    /**
65
     * @deprecated
66
     *
67
     * @return string
68
     */
69 7
    public function __toString(): string
70
    {
71 7
        return $this->id;
72
    }
73
}
74