Completed
Push — master ( e6854c...b0ed9c )
by Julián
05:36
created

GenericSnapshot::fromAggregateRoot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * event-sourcing (https://github.com/phpgears/event-sourcing).
5
 * Event Sourcing base.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/event-sourcing
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\EventSourcing\Store\Snapshot;
15
16
use Gears\EventSourcing\Aggregate\AggregateRoot;
17
use Gears\EventSourcing\Store\GenericStoreStream;
18
use Gears\EventSourcing\Store\StoreStream;
19
20
/**
21
 * Generic Snapshot.
22
 */
23
final class GenericSnapshot implements Snapshot
24
{
25
    /**
26
     * @var StoreStream
27
     */
28
    private $stream;
29
30
    /**
31
     * @var AggregateRoot
32
     */
33
    private $aggregateRoot;
34
35
    /**
36
     * GenericSnapshot constructor.
37
     *
38
     * @param StoreStream   $stream
39
     * @param AggregateRoot $aggregateRoot
40
     */
41
    private function __construct(StoreStream $stream, AggregateRoot $aggregateRoot)
42
    {
43
        $this->stream = $stream;
44
        $this->aggregateRoot = $aggregateRoot;
45
    }
46
47
    /**
48
     * Create from aggregateRoot.
49
     *
50
     * @param AggregateRoot $aggregateRoot
51
     *
52
     * @return self
53
     */
54
    public static function fromAggregateRoot(AggregateRoot $aggregateRoot): self
55
    {
56
        return new self(GenericStoreStream::fromAggregateRoot($aggregateRoot), $aggregateRoot);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getStoreStream(): StoreStream
63
    {
64
        return $this->stream;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getAggregateRoot(): AggregateRoot
71
    {
72
        return $this->aggregateRoot;
73
    }
74
}
75