DomainEventMiddleware::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * GpsLab component.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/MIT
9
 */
10
11
namespace GpsLab\Component\Middleware\DomainEvent;
12
13
use GpsLab\Component\Middleware\Middleware;
14
use GpsLab\Domain\Event\Bus\EventBus;
15
use GpsLab\Domain\Event\Event;
16
17
class DomainEventMiddleware implements Middleware
18
{
19
    /**
20
     * @var EventBus
21
     */
22
    private $bus;
23
24
    /**
25
     * @param EventBus $bus
26
     */
27 2
    public function __construct(EventBus $bus)
28
    {
29 2
        $this->bus = $bus;
30 2
    }
31
32
    /**
33
     * @param mixed    $message
34
     * @param callable $next
35
     *
36
     * @return mixed
37
     */
38 2
    public function handle($message, callable $next)
39
    {
40 2
        if ($message instanceof Event) {
41 1
            return $next($this->bus->publish($message));
42
        }
43
44 1
        return $next($message);
45
    }
46
}
47