CompositePolicy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
wmc 6
lcom 1
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A shouldCreateSnapshot() 0 10 3
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