Producer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 77
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getContentType() 0 4 1
A setContentType() 0 6 1
A getDeliveryMode() 0 4 1
A setDeliveryMode() 0 6 1
A publish() 0 18 2
1
<?php
2
3
namespace RabbitMqModule;
4
5
use PhpAmqpLib\Message\AMQPMessage;
6
7
/**
8
 * Class Producer
9
 * @package RabbitMqModule
10
 */
11
class Producer extends BaseAmqp implements ProducerInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $contentType = 'text/plain';
17
    /**
18
     * @var int
19
     */
20
    protected $deliveryMode = 2;
21
22
    /**
23
     * @return string
24
     */
25 2
    public function getContentType()
26
    {
27 2
        return $this->contentType;
28
    }
29
30
    /**
31
     * @param string $contentType
32
     *
33
     * @return $this
34
     */
35 1
    public function setContentType($contentType)
36
    {
37 1
        $this->contentType = $contentType;
38
39 1
        return $this;
40
    }
41
42
    /**
43
     * @return int
44
     */
45 2
    public function getDeliveryMode()
46
    {
47 2
        return $this->deliveryMode;
48
    }
49
50
    /**
51
     * @param int $deliveryMode
52
     *
53
     * @return $this
54
     */
55 1
    public function setDeliveryMode($deliveryMode)
56
    {
57 1
        $this->deliveryMode = $deliveryMode;
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * @param string $body
64
     * @param string $routingKey
65
     * @param array  $properties
66
     *
67
     * @return $this
68
     */
69 1
    public function publish($body, $routingKey = '', array $properties = [])
70
    {
71 1
        if ($this->isAutoSetupFabricEnabled()) {
72 1
            $this->setupFabric();
73 1
        }
74 1
        $properties = array_merge(
75 1
            ['content_type' => $this->getContentType(), 'delivery_mode' => $this->getDeliveryMode()],
76
            $properties
77 1
        );
78 1
        $message = new AMQPMessage((string) $body, $properties);
79 1
        $this->getChannel()->basic_publish(
80 1
            $message,
81 1
            $this->getExchangeOptions()->getName(),
82
            (string) $routingKey
83 1
        );
84
85 1
        return $this;
86
    }
87
}
88