DefaultMessageComposer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3
ccs 9
cts 9
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compose() 0 11 1
A serialize() 0 4 1
1
<?php
2
3
namespace TreeHouse\Queue\Message\Composer;
4
5
use TreeHouse\Queue\Message\Message;
6
use TreeHouse\Queue\Message\MessageProperties;
7
use TreeHouse\Queue\Message\Serializer\SerializerInterface;
8
9
class DefaultMessageComposer implements MessageComposerInterface
10
{
11
    /**
12
     * @var SerializerInterface
13
     */
14
    protected $serializer;
15
16
    /**
17
     * @param SerializerInterface $serializer
18
     */
19 14
    public function __construct(SerializerInterface $serializer)
20
    {
21 14
        $this->serializer = $serializer;
22 14
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27 12
    public function compose($payload, array $properties = [], $id = null, $routingKey = null)
28
    {
29
        $defaults = [
30 12
            'content_type' => MessageProperties::CONTENT_TYPE_TEXT_PLAIN,
31
            'delivery_mode' => MessageProperties::DELIVERY_MODE_PERSISTENT,
32
        ];
33
34 12
        $properties = new MessageProperties(array_merge($defaults, $properties));
35
36 12
        return new Message($this->serialize($payload), $properties, $id, $routingKey);
37
    }
38
39
    /**
40
     * @param mixed $payload
41
     *
42
     * @return string
43
     */
44 9
    protected function serialize($payload)
45
    {
46 9
        return $this->serializer->serialize($payload);
47
    }
48
}
49