AggregateId::toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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