ApplicationEventPublisher::publish()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
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
}