Snapshotter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addSnapshotTranslator() 0 4 1
A takeSnapshot() 0 4 1
A translateSnapshot() 0 4 1
1
<?php
2
3
namespace DDDominio\EventSourcing\Snapshotting;
4
5
use DDDominio\EventSourcing\Common\EventSourcedAggregateRootInterface;
6
7
class Snapshotter
8
{
9
    private $snapshotStrategies = [];
10
11
    /**
12
     * @param string $aggregateClass
13
     * @param ReflectionSnapshotTranslator $snapshotStrategy
14
     */
15 3
    public function addSnapshotTranslator($aggregateClass, $snapshotStrategy)
16
    {
17 3
        $this->snapshotStrategies[$aggregateClass] = $snapshotStrategy;
18 3
    }
19
20
    /**
21
     * @param EventSourcedAggregateRootInterface $aggregate
22
     * @return SnapshotInterface
23
     */
24 1
    public function takeSnapshot($aggregate)
25
    {
26 1
        return $this->snapshotStrategies[get_class($aggregate)]->buildSnapshotFromAggregate($aggregate);
27
    }
28
29
    /**
30
     * @param SnapshotInterface $snapshot
31
     * @return EventSourcedAggregateRootInterface
32
     */
33 2
    public function translateSnapshot($snapshot)
34
    {
35 2
        return $this->snapshotStrategies[$snapshot->aggregateClass()]->buildAggregateFromSnapshot($snapshot);
36
    }
37
}
38