ApplicationEventPublisher   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A publish() 0 7 2
A __construct() 0 5 1
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
}