__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\EventSource\Infrastructure\Bus;
6
7
use Antidot\EventSource\Domain\Event\AggregateChanged;
8
use Antidot\EventSource\Domain\Event\DomainEventEmitter;
9
use League\Tactician\Middleware;
10
use Psr\EventDispatcher\EventDispatcherInterface;
11
12
class TacticianDomainEventDispatcherMiddleware implements Middleware
13
{
14
    private EventDispatcherInterface $dispatcher;
15
16
    public function __construct(EventDispatcherInterface $dispatcher)
17
    {
18
        $this->dispatcher = $dispatcher;
19
    }
20
21
    public function execute($command, callable $next)
22
    {
23
        /** @var mixed $result */
24
        $result = $next($command);
25
        /** @var AggregateChanged $event */
26
        foreach (DomainEventEmitter::emit() as $event) {
27
            $this->dispatcher->dispatch($event);
28
        }
29
30
        return $result;
31
    }
32
}
33