Snapshot::getAggregate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Domain\Snapshotting;
4
5
use Domain\Aggregates\AggregateRoot;
6
use Domain\Eventing\CommittedEvents;
7
8
/**
9
 * @author Sebastiaan Hilbers <[email protected]>
10
 */
11
class Snapshot
12
{
13
    private $version;
14
15
    private $aggregate;
16
17
    private $creationDate;
18
19
    public function __construct(AggregateRoot $aggregate, $version, $creationDate)
20
    {
21
        $this->aggregate = $aggregate;
22
        $this->version = $version;
23
        $this->creationDate = $creationDate;
24
    }
25
26
    /**
27
     * Get the aggregate root
28
     *
29
     * @return AggregateRoot
30
     */
31
    public function getAggregate()
32
    {
33
        return $this->aggregate;
34
    }
35
36
    public function getVersion()
37
    {
38
        return $this->version;
39
    }
40
41
    public function getCreationDate()
42
    {
43
        return $this->creationDate;
44
    }
45
46
    /**
47
     * Apply missing events that were commited to the event store since this snapshot was made
48
     *
49
     * @param \Domain\Snapshotting\CommitedEvents $events
50
     */
51
    public function correctMissingHistory(CommittedEvents $events)
52
    {
53
        $this->aggregate->whenAll($events);
54
55
        return $this;
56
    }
57
}
58