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

AggregateId::toString()   A

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
     * @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