EventQueueProducer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 13
c 1
b 0
f 1
dl 0
loc 49
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A enqueue() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jellyfish\Event;
6
7
use Jellyfish\Queue\DestinationFactoryInterface;
8
use Jellyfish\Queue\DestinationInterface;
9
use Jellyfish\Queue\QueueClientInterface;
10
11
class EventQueueProducer implements EventQueueProducerInterface
12
{
13
    /**
14
     * @var \Jellyfish\Event\EventMapperInterface
15
     */
16
    protected $eventMapper;
17
18
    /**
19
     * @var \Jellyfish\Queue\QueueClientInterface
20
     */
21
    protected $queueClient;
22
23
    /**
24
     * @var \Jellyfish\Queue\DestinationFactoryInterface
25
     */
26
    protected $destinationFactory;
27
28
    /**
29
     * @param \Jellyfish\Event\EventMapperInterface $eventMapper
30
     * @param \Jellyfish\Queue\QueueClientInterface $queueClient
31
     * @param \Jellyfish\Queue\DestinationFactoryInterface $destinationFactory
32
     */
33
    public function __construct(
34
        EventMapperInterface $eventMapper,
35
        QueueClientInterface $queueClient,
36
        DestinationFactoryInterface $destinationFactory
37
    ) {
38
        $this->eventMapper = $eventMapper;
39
        $this->queueClient = $queueClient;
40
        $this->destinationFactory = $destinationFactory;
41
    }
42
43
    /**
44
     * @param \Jellyfish\Event\EventInterface $event
45
     *
46
     * @return \Jellyfish\Event\EventQueueProducerInterface
47
     */
48
    public function enqueue(
49
        EventInterface $event
50
    ): EventQueueProducerInterface {
51
        $destination = $this->destinationFactory->create()
52
            ->setName($event->getName())
53
            ->setType(DestinationInterface::TYPE_FANOUT);
54
55
        $message = $this->eventMapper->toMessage($event);
56
57
        $this->queueClient->sendMessage($destination, $message);
58
59
        return $this;
60
    }
61
}
62