ExtendableEnvelopeConsumer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 47
ccs 5
cts 10
cp 0.5
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A consume() 0 11 1
1
<?php
2
3
namespace Happyr\Mq2phpBundle\Consumer;
4
5
use Happyr\Mq2phpBundle\Event\PreHandleMessage;
6
use SimpleBus\Serialization\Envelope\Serializer\MessageInEnvelopeSerializer;
7
use SimpleBus\Message\Bus\MessageBus;
8
use SimpleBus\Asynchronous\Consumer\SerializedEnvelopeConsumer as SimpleBusSerializedEnvelopeConsumer;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
11
/**
12
 * Use this consumer to easily implement an asynchronous message consumer.
13
 */
14
class ExtendableEnvelopeConsumer implements SimpleBusSerializedEnvelopeConsumer
15
{
16
    /**
17
     * @var MessageInEnvelopeSerializer
18
     */
19
    private $messageInEnvelopeSerializer;
20
21
    /**
22
     * @var MessageBus
23
     */
24
    private $messageBus;
25
26
    /**
27
     * @var EventDispatcherInterface
28
     */
29
    private $dispathcer;
30
31
    /**
32
     * @param MessageInEnvelopeSerializer $messageInEnvelopeSerializer
33
     * @param MessageBus                 $messageBus
34
     * @param EventDispatcherInterface   $dispathcer
35
     */
36 1
    public function __construct(
37
        MessageInEnvelopeSerializer $messageInEnvelopeSerializer,
38
        MessageBus $messageBus,
39
        EventDispatcherInterface $dispathcer
40
    ) {
41 1
        $this->messageInEnvelopeSerializer = $messageInEnvelopeSerializer;
42 1
        $this->messageBus = $messageBus;
43 1
        $this->dispathcer = $dispathcer;
44 1
    }
45
46
    /**
47
     * @param string $serializedEnvelope
48
     */
49
    public function consume($serializedEnvelope)
50
    {
51
        // Unserialize
52
        $envelope = $this->messageInEnvelopeSerializer->unwrapAndDeserialize($serializedEnvelope);
53
54
        // Tell the world
55
        $this->dispathcer->dispatch(PreHandleMessage::NAME, new PreHandleMessage($envelope));
56
57
        // Handle the message
58
        $this->messageBus->handle($envelope->message());
59
    }
60
}
61