Passed
Pull Request — master (#84)
by Frank
10:15 queued 08:09
created

AggregateAppliesKnownEvents   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
trait AggregateAppliesKnownEvents
8
{
9
    private $aggregateRootVersion = 0;
10
11 1
    public function apply(object $event): void
12
    {
13 1
        static $hasMethodCache = [];
14 1
        $parts = explode('\\', get_class($event));
15 1
        $methodName = 'apply' . end($parts);
16 1
        $shouldApply = $hasMethodCache[$methodName] ?? method_exists($this, $methodName);
17
18 1
        if ($shouldApply) {
19 1
            $this->{$methodName}($event);
20
        }
21
22 1
        ++$this->aggregateRootVersion;
23 1
    }
24
}
25