Completed
Push — master ( de5c9f...2ef464 )
by Daniel
21s queued 11s
created

EventQueueProducer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

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

2 Methods

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