RabbitMqSendDriver::send()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Gendoria\CommandQueueRabbitMqDriverBundle\SendDriver;
4
5
use Gendoria\CommandQueue\Command\CommandInterface;
6
use Gendoria\CommandQueue\SendDriver\SendDriverInterface;
7
use Gendoria\CommandQueue\Serializer\SerializerInterface;
8
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
9
10
/**
11
 * Command queue send driver using RabbitMQ server.
12
 *
13
 * @author Tomasz Struczyński <[email protected]>
14
 */
15
class RabbitMqSendDriver implements SendDriverInterface
16
{
17
    /**
18
     * Serializer instance.
19
     *
20
     * @var SerializerInterface
21
     */
22
    private $serializer;
23
24
    /**
25
     * Producer instance.
26
     *
27
     * @var ProducerInterface
28
     */
29
    private $producer;
30
31
    /**
32
     * Class constructor.
33
     *
34
     * @param SerializerInterface $serializer
35
     * @param ProducerInterface   $producer
36
     */
37 1
    public function __construct(SerializerInterface $serializer, ProducerInterface $producer)
38
    {
39 1
        $this->serializer = $serializer;
40 1
        $this->producer = $producer;
41 1
    }
42
43
    /**
44
     * Send command using RabbitMQ server.
45
     *
46
     * {@inheritdoc}
47
     */
48 1
    public function send(CommandInterface $command)
49
    {
50 1
        $serialized = $this->serializer->serialize($command);
51 1
        $this->producer->publish(
52 1
            $serialized->getSerializedCommand(),
53 1
            $serialized->getCommandClass(),
54
            array(
55
                'application_headers' => array(
56
                    'x-class-name' => array(
57 1
                        'S',
58 1
                        $serialized->getCommandClass(),
59 1
                    ),
60 1
                ),
61
            )
62 1
        );
63 1
    }
64
}
65