| Total Complexity | 5 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | final class GenericSnapshot implements Snapshot |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var StoreStream |
||
| 28 | */ |
||
| 29 | private $storeStream; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var AggregateRoot |
||
| 33 | */ |
||
| 34 | private $aggregateRoot; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * GenericSnapshot constructor. |
||
| 38 | * |
||
| 39 | * @param AggregateRoot $aggregateRoot |
||
| 40 | * |
||
| 41 | * @throws SnapshotStoreException |
||
| 42 | */ |
||
| 43 | public function __construct(AggregateRoot $aggregateRoot) |
||
| 44 | { |
||
| 45 | if ($aggregateRoot->getRecordedAggregateEvents()->count() !== 0 |
||
| 46 | || $aggregateRoot->getRecordedEvents()->count() !== 0 |
||
| 47 | ) { |
||
| 48 | throw new SnapshotStoreException('Cannot create an snapshot of an Aggregate root with recorded events'); |
||
| 49 | } |
||
| 50 | |||
| 51 | $this->storeStream = GenericStoreStream::fromAggregateRoot($aggregateRoot); |
||
| 52 | $this->aggregateRoot = $aggregateRoot; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | public function getStoreStream(): StoreStream |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | public function getAggregateRoot(): AggregateRoot |
||
| 71 |