Snapshotter::translateSnapshot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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