AggregateBehavior   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 46
ccs 12
cts 14
cp 0.8571
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteChildEntity() 0 3 1
A isNew() 0 3 1
A markAsPersisted() 0 3 1
A aggregateVersion() 0 3 1
A deletedChildEntities() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace TalisOrm;
5
6
use TalisOrm\DomainEvents\EventRecordingCapabilities;
7
8
trait AggregateBehavior
9
{
10
    use EventRecordingCapabilities;
11
12
    /**
13
     * @var ChildEntity[]
14
     */
15
    private $deletedChildEntities = [];
16
17
    /**
18
     * @var bool
19
     */
20
    private $isNew = true;
21
22
    /**
23
     * @var int
24
     */
25
    private $aggregateVersion = 0;
26
27 26
    public function deletedChildEntities(): array
28
    {
29 26
        $deletedChildEntities = $this->deletedChildEntities;
30
31 26
        $this->deletedChildEntities = [];
32
33 26
        return $deletedChildEntities;
34
    }
35
36 2
    private function deleteChildEntity(ChildEntity $childEntity): void
37
    {
38 2
        $this->deletedChildEntities[] = $childEntity;
39 2
    }
40
41 26
    public function isNew(): bool
42
    {
43 26
        return $this->isNew;
44
    }
45
46 24
    public function markAsPersisted(): void
47
    {
48 24
        $this->isNew = false;
49 24
    }
50
51
    public function aggregateVersion(): int
52
    {
53
        return $this->aggregateVersion;
54
    }
55
}
56