Completed
Pull Request — master (#66)
by Frank
04:43 queued 02:26
created

AggregateRootBehaviourWithRequiredHistory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A reconstituteFromEvents() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
use Generator;
8
9
trait AggregateRootBehaviourWithRequiredHistory
10
{
11
    use AggregateRootBehaviour {
12
        AggregateRootBehaviour::reconstituteFromEvents as private defaultAggregateRootReconstitute;
13
    }
14
15
    public static function reconstituteFromEvents(AggregateRootId $aggregateRootId, Generator $events): AggregateRoot
16
    {
17
        $aggregateRoot = static::defaultAggregateRootReconstitute($aggregateRootId, $events);
18
19
        if (0 === $aggregateRoot->aggregateRootVersion()) {
20
            throw new InvalidAggregateRootReconstitutionException();
21
        }
22
23
        return $aggregateRoot;
24
    }
25
}
26