Passed
Push — master ( 68b614...6c4a2e )
by Matthias
02:28 queued 01:08
created

AggregateBehavior::aggregateVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace TalisOrm;
5
6
use TalisOrm\DomainEvents\EventRecordingCapabilities;
7
use Webmozart\Assert\Assert;
8
9
trait AggregateBehavior
10
{
11
    use EventRecordingCapabilities;
12
13
    /**
14
     * @var array
15
     */
16
    private $deletedChildEntities = [];
17
18
    /**
19
     * @var bool
20
     */
21
    private $isNew = true;
22
23
    /**
24
     * @var int
25
     */
26
    private $aggregateVersion = 0;
27
28 26
    public function deletedChildEntities(): array
29
    {
30 26
        $deletedChildEntities = $this->deletedChildEntities;
31
32 26
        $this->deletedChildEntities = [];
33
34 26
        return $deletedChildEntities;
35
    }
36
37 2
    private function deleteChildEntity(ChildEntity $childEntity)
38
    {
39 2
        $this->deletedChildEntities[] = $childEntity;
40 2
    }
41
42 26
    public function isNew(): bool
43
    {
44 26
        return $this->isNew;
45
    }
46
47 24
    public function markAsPersisted(): void
48
    {
49 24
        $this->isNew = false;
50 24
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function aggregateVersion()
56
    {
57
        return $this->aggregateVersion;
58
    }
59
}
60