AggregateId   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 33
ccs 9
cts 9
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A new() 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
     * @return static
32
     */
33 10
    public static function new(): self
34
    {
35 10
        return new static(uuid());
36
    }
37
38
    /**
39
     * @throws \ServiceBus\EventSourcing\Exceptions\InvalidAggregateIdentifier
40
     */
41 11
    final public function __construct(string $id)
42
    {
43 11
        if ('' === $id)
44
        {
45 1
            throw InvalidAggregateIdentifier::emptyId();
46
        }
47
48 10
        $this->id = $id;
49 10
    }
50
51 10
    public function toString(): string
52
    {
53 10
        return $this->id;
54
    }
55
}
56