ReconstituteFromIsSimple   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 1
b 0
f 0
dl 0
loc 12
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A reconstituteFrom() 0 8 2
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