Completed
Push — master ( 613d98...fa04c9 )
by Rémi
20:40
created

SerializingPublisher::publish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace Burrow\Publisher;
4
5
use Burrow\QueuePublisher;
6
use Burrow\Serializer;
7
8
class SerializingPublisher implements QueuePublisher
9
{
10
    /** @var QueuePublisher */
11
    private $publisher;
12
13
    /** @var Serializer */
14
    private $serializer;
15
16
    /**
17
     * SerializingPublisher constructor.
18
     *
19
     * @param QueuePublisher $publisher
20
     * @param Serializer     $serializer
21
     */
22
    public function __construct(
23
        QueuePublisher $publisher,
24
        Serializer $serializer
25
    ) {
26
        $this->publisher = $publisher;
27
        $this->serializer = $serializer;
28
    }
29
30
    /**
31
     * Publish a message on the queue
32
     *
33
     * @param mixed    $data
34
     * @param string   $routingKey
35
     * @param string[] $headers
36
     *
37
     * @return mixed
38
     */
39
    public function publish($data, $routingKey = '', array $headers = [])
40
    {
41
        $returnValue = $this->publisher->publish(
42
            $this->serializer->serialize($data),
43
            $routingKey,
44
            $headers
45
        );
46
47
        return $this->serializer->deserialize($returnValue);
48
    }
49
}
50