ApplicationEventPublisher::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Infrastructure\Events\Api;
4
5
use App\Infrastructure\Events\ApplicationOutboundEvent;
6
use App\Infrastructure\Events\EventIdHolder;
7
use Psr\Log\LoggerInterface;
8
use Symfony\Component\Messenger\MessageBusInterface;
9
10
/**
11
 * Implementation of the Event Publisher based on Symfony Messenger
12
 */
13
class ApplicationEventPublisher implements ApplicationEventPublisherInterface
14
{
15
16 2
    public function __construct(
17
        private MessageBusInterface $messageBus,
18
        private LoggerInterface     $logger
19
    )
20
    {
21 2
    }
22
23 2
    public function publish(ApplicationOutboundEvent $event)
24
    {
25 2
        if (EventIdHolder::isSet()) {
26 2
            $event->setEventId(EventIdHolder::get());
27
        }
28 2
        $this->logger->info(sprintf("[event]: Publishing Outbound Event %s(%s)", $event::class, $event));
29 2
        $this->messageBus->dispatch($event);
30 2
    }
31
32
}