CompositeSnapshottingPolicy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A shouldCreateSnapshot() 0 10 3
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Domain\EventSourcing\Snapshot\Policy;
11
12
use Cubiche\Domain\EventSourcing\EventSourcedAggregateRootInterface;
13
14
/**
15
 * CompositeSnapshottingPolicy class.
16
 *
17
 * @author Ivannis Suárez Jerez <[email protected]>
18
 */
19
class CompositeSnapshottingPolicy implements SnapshottingPolicyInterface
20
{
21
    /**
22
     * @var SnapshottingPolicyInterface[]
23
     */
24
    protected $policies = [];
25
26
    /**
27
     * CompositeSnapshottingPolicy constructor.
28
     *
29
     * @param SnapshottingPolicyInterface[] $policies
30
     */
31
    public function __construct(array $policies)
32
    {
33
        foreach ($policies as $policy) {
34
            if (!$policy instanceof SnapshottingPolicyInterface) {
35
                throw new \InvalidArgumentException();
36
            }
37
38
            $this->policies[] = $policy;
39
        }
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function shouldCreateSnapshot(EventSourcedAggregateRootInterface $eventSourcedAggregateRoot)
46
    {
47
        foreach ($this->policies as $policy) {
48
            if (!$policy->shouldCreateSnapshot($eventSourcedAggregateRoot)) {
49
                return false;
50
            }
51
        }
52
53
        return true;
54
    }
55
}
56