Conditions | 3 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 7 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
37 | public static function reconstituteFromSnapshotAndEvents(Snapshot $snapshot, Generator $events): AggregateRoot |
||
38 | { |
||
39 | $id = $snapshot->aggregateRootId(); |
||
40 | /** @var static&AggregateRoot $aggregateRoot */ |
||
41 | $aggregateRoot = static::reconstituteFromSnapshotState($id, $snapshot->state()); |
||
42 | $aggregateRoot->aggregateRootVersion = $snapshot->aggregateRootVersion(); |
||
43 | |||
44 | foreach ($events as $event) { |
||
45 | $aggregateRoot->apply($event); |
||
46 | } |
||
47 | |||
48 | $aggregateRoot->aggregateRootVersion = $events->getReturn() ?: $aggregateRoot->aggregateRootVersion; |
||
49 | |||
50 | return $aggregateRoot; |
||
51 | } |
||
55 |