BaseAggregateRoot::bumpVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Domain\Aggregates;
4
5
use Domain\Identity\Identity;
6
use Domain\Eventing\When\ConventionBasedWhen;
7
8
/**
9
 * @author Sebastiaan Hilbers <[email protected]>
10
 */
11
abstract class BaseAggregateRoot implements AggregateRoot
12
{
13
    /**
14
     * Some functionality is coming from traits :)
15
     */
16
    use Reconstitution;
17
    use EventSourced;
18
    use ConventionBasedWhen;
19
20
    /**
21
     * @var Identity
22
     */
23
    private $identity;
24
25
    /**
26
     * @var int
27
     */
28
    private $version = 0;
29
30
    /**
31
     * @param Identity $id
32
     */
33
    protected function __construct(Identity $id)
34
    {
35
        $this->identity = $id;
36
    }
37
38
    /**
39
     * Gets the identity
40
     *
41
     * @param Identity $id
42
     * @return static
43
     */
44
    public static function fromIdentity(Identity $id)
45
    {
46
        return new static($id);
47
    }
48
49
    /**
50
     * Get the identity
51
     *
52
     * @return Identity
53
     */
54
    public function getIdentity()
55
    {
56
        return $this->identity;
57
    }
58
59
    /**
60
     * Increment the aggregate's version
61
     *
62
     * @return $this
63
     */
64
    protected function bumpVersion()
65
    {
66
        $this->version++;
67
68
        return $this;
69
    }
70
71
    /**
72
     * Get aggregate version
73
     *
74
     * @return int
75
     */
76
    public function getVersion()
77
    {
78
        return $this->version;
79
    }
80
}
81