Reconstitution   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 31
wmc 1
lcom 0
cbo 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reconstituteFrom() 0 7 1
whenAll() 0 1 ?
fromIdentity() 0 1 ?
1
<?php
2
3
namespace Domain\Aggregates;
4
5
use Domain\Eventing\CommittedEvents;
6
use Domain\Identity\Identity;
7
8
/**
9
 * Sane default behaviour and state for Reconstituable aggregates
10
 *
11
 * @author Sebastiaan Hilbers <[email protected]>
12
 */
13
trait Reconstitution
14
{
15
    /**
16
     * Reconstructs given concrete aggregate and applies the history
17
     *
18
     * @param CommittedEvents $history
19
     * @return static
20
     */
21
    public static function reconstituteFrom(CommittedEvents $history)
22
    {
23
        $instance = static::fromIdentity($history->getIdentity());
24
        $instance->whenAll($history);
25
26
        return $instance;
27
    }
28
29
    /**
30
     * This trait requires a whenAll method on the concrete class
31
     *
32
     * @param $events
33
     */
34
    abstract protected function whenAll(CommittedEvents $events);
35
36
    /**
37
     * This trait requires a fromIdentity method on the concrete class
38
     *
39
     * @param Identity $identity
40
     * @return Aggregate
41
     */
42
    abstract public static function fromIdentity(Identity $identity);
43
}
44