CompositePolicy::shouldCreateSnapshot()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Domain\Snapshotting;
4
5
use Domain\Aggregates\AggregateRoot;
6
7
class CompositePolicy implements SnapshottingPolicy
8
{
9
    protected $policies = [];
10
11
    public function __construct(array $policies)
12
    {
13
        foreach ($policies as $policy) {
14
            if (!$policy instanceof SnapshottingPolicy) {
15
                throw new \InvalidArgumentException;
16
            }
17
        }
18
19
        $this->policies = $policies;
20
    }
21
22
    public function shouldCreateSnapshot(AggregateRoot $root)
23
    {
24
        foreach ($this->policies as $policy) {
25
            if (!$policy->shouldCreateSnapshot($root)) {
26
                return false;
27
            }
28
        }
29
30
        return true;
31
    }
32
}
33