ConventionBasedWhen   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 29
wmc 7
lcom 0
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A when() 0 7 2
A whenAll() 0 6 2
1
<?php
2
3
namespace Domain\Eventing\When;
4
5
use Domain\Eventing\DomainEvent;
6
use Domain\Tools\ClassToString;
7
use Domain\Eventing\CommittedEvents;
8
9
/**
10
 * @author Sebastiaan Hilbers <[email protected]>
11
 */
12
trait ConventionBasedWhen
13
{
14
    /**
15
     * Handle a single domain event
16
     *
17
     * @param DomainEvent $event
18
     * @return void
19
     */
20
    protected function when(DomainEvent $event)
21
    {
22
        $method = 'when' . ClassToString::short($event);
23
        if (is_callable([$this, $method])) {
24
            $this->{$method}($event);
25
        }
26
    }
27
28
    /**
29
     * Handle a committed event stream
30
     *
31
     * @param CommittedEvents $events
32
     * @return void
33
     */
34
    protected function whenAll(CommittedEvents $events)
35
    {
36
        foreach ($events as $event) {
37
            $this->when($event);
38
        }
39
    }
40
}
41