Snapshot   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A snapshotName() 0 4 1
A aggregate() 0 4 1
A version() 0 4 1
A createdAt() 0 4 1
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cubiche\Domain\EventSourcing\Snapshot;
12
13
use Cubiche\Core\Serializer\SerializableInterface;
14
use Cubiche\Domain\EventSourcing\EventSourcedAggregateRootInterface;
15
use Cubiche\Domain\EventSourcing\Versioning\Version;
16
17
/**
18
 * Snapshot class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class Snapshot implements SerializableInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    protected $snapshotName;
28
29
    /**
30
     * @var EventSourcedAggregateRootInterface
31
     */
32
    protected $aggregate;
33
34
    /**
35
     * @var int
36
     */
37
    protected $version;
38
39
    /**
40
     * @var \DateTime
41
     */
42
    protected $createdAt;
43
44
    /**
45
     * Snapshot constructor.
46
     *
47
     * @param string                             $snapshotName
48
     * @param EventSourcedAggregateRootInterface $aggregate
49
     */
50
    public function __construct($snapshotName, EventSourcedAggregateRootInterface $aggregate)
51
    {
52
        $this->snapshotName = $snapshotName;
53
        $this->aggregate = $aggregate;
54
        $this->version = $aggregate->version();
55
        $this->createdAt = new \DateTime();
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function snapshotName()
62
    {
63
        return $this->snapshotName;
64
    }
65
66
    /**
67
     * @return EventSourcedAggregateRootInterface
68
     */
69
    public function aggregate()
70
    {
71
        return $this->aggregate;
72
    }
73
74
    /**
75
     * @return Version
76
     */
77
    public function version()
78
    {
79
        return $this->version;
80
    }
81
82
    /**
83
     * @return \DateTime
84
     */
85
    public function createdAt()
86
    {
87
        return $this->createdAt;
88
    }
89
}
90