Passed
Push — master ( cbefbc...3619f4 )
by Frank
16:49 queued 06:49
created

AggregateAlwaysAppliesEvents   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
/**
8
 * This trait calls the apply[EventClassName] method
9
 * for every event it receives. Use this trait if
10
 * you want to ensure that you do not miss responding
11
 * to any type of event you raise in the aggregate.
12
 */
13
trait AggregateAlwaysAppliesEvents
14
{
15
    private int $aggregateRootVersion = 0;
16
17
    protected function apply(object $event): void
18
    {
19
        $parts = explode('\\', get_class($event));
20
        $this->{'apply' . end($parts)}($event);
21
        ++$this->aggregateRootVersion;
22
    }
23
}
24