Snapshot   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 47
wmc 5
lcom 1
cbo 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getAggregate() 0 4 1
A getVersion() 0 4 1
A getCreationDate() 0 4 1
A correctMissingHistory() 0 6 1
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