ApplyCallsWhenMethod::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
namespace Kepawni\Twilted\Basic;
3
4
use Kepawni\Twilted\DomainEvent;
5
use Verraes\ClassFunctions\ClassFunctions;
6
7
trait ApplyCallsWhenMethod
8
{
9
    /**
10
     * Delegate the application of the event to the appropriate when... method, e. g. a VisitorHasLeft event will be
11
     * processed by the (private) method whenVisitorHasLeft(VisitorHasLeft $event): void
12
     *
13
     * @param DomainEvent $event
14
     */
15
    protected function apply(DomainEvent $event): void
16
    {
17
        $method = 'when' . ClassFunctions::short($event->getPayload());
18
        $this->$method($event->getPayload(), $event);
19
    }
20
}
21