Completed
Push — v4.0 ( 989be1...ff495d )
by Masiukevich
02:21
created

AggregateCreated::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
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\Contract;
14
15
use function ServiceBus\Common\datetimeInstantiator;
16
use ServiceBus\EventSourcing\AggregateId;
17
18
/**
19
 * New aggregate created.
20
 *
21
 * @psalm-readonly
22
 */
23
final class AggregateCreated
24
{
25
    /**
26
     * Aggregate identifier.
27
     *
28
     * @var string
29
     */
30
    public string $id;
31
32
    /**
33
     * Aggregate identifier class.
34
     *
35
     * @psalm-var class-string<\ServiceBus\EventSourcing\AggregateId>
36
     *
37
     * @var string
38
     */
39
    public string $idClass;
40
41
    /**
42
     * Aggregate class.
43
     *
44
     * @psalm-var class-string<\ServiceBus\EventSourcing\Aggregate>
45
     *
46
     * @var string
47
     */
48
    public string $aggregateClass;
49
50
    /**
51
     * Operation datetime.
52
     *
53
     * @var \DateTimeImmutable
54
     */
55
    public \DateTimeImmutable $datetime;
56
57
    /**
58
     * @psalm-param class-string<\ServiceBus\EventSourcing\Aggregate> $aggregateClass
59
     */
60 10
    public function __construct(AggregateId $id, string $aggregateClass)
61
    {
62
        /** @psalm-var class-string<\ServiceBus\EventSourcing\AggregateId> $idClass */
63 10
        $idClass = (string) \get_class($id);
64
65 10
        $this->id             = $id->toString();
66 10
        $this->idClass        = $idClass;
67 10
        $this->aggregateClass = $aggregateClass;
68
69
        /** @var \DateTimeImmutable $currentDate */
70 10
        $currentDate = datetimeInstantiator('NOW');
71
72 10
        $this->datetime = $currentDate;
73 10
    }
74
}
75