CommandToEventGlue::__construct()   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
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Infrastructure\DomainEvents;
4
5
use Stratadox\CardGame\EventBag;
6
use Stratadox\CommandHandling\Middleware;
7
8
final class CommandToEventGlue implements Middleware
9
{
10
    private $eventBag;
11
    private $dispatcher;
12
13
    public function __construct(EventBag $eventBag, Dispatcher $dispatcher)
14
    {
15
        $this->eventBag = $eventBag;
16
        $this->dispatcher = $dispatcher;
17
    }
18
19
    public function invoke(object $command): void
20
    {
21
        foreach ($this->eventBag->all() as $domainEvent) {
22
            $this->dispatcher->dispatch($domainEvent);
23
        }
24
        $this->eventBag->clear();
25
    }
26
}
27