ReconstituteFromIsSimple::reconstituteFrom()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
1
<?php declare(strict_types=1);
2
namespace Kepawni\Twilted\Basic;
3
4
use Kepawni\Twilted\AggregateRoot;
5
use Kepawni\Twilted\EntityHistory;
6
use Kepawni\Twilted\EntityIdentifier;
7
use Kepawni\Twilted\EventSourcedEntity;
8
9
trait ReconstituteFromIsSimple
10
{
11
    abstract protected function __construct(EntityIdentifier $id);
12
13
    public static function reconstituteFrom(EntityHistory $history): EventSourcedEntity
14
    {
15
        /** @var AggregateRoot $aggregate */
16
        $aggregate = new static($history->getId());
17
        foreach ($history as $event) {
18
            $aggregate->apply($event);
19
        }
20
        return $aggregate;
21
    }
22
}
23