Completed
Push — master ( a3bee9...bbaea8 )
by Tomáš
07:16
created

AbstractProducer::produce()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 5
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Portiny\RabbitMQ\Producer;
4
5
use Bunny\Channel;
6
use React\Promise\PromiseInterface;
7
8
abstract class AbstractProducer
9
{
10
	/**
11
	 * @var int
12
	 */
13
	public const DELIVERY_MODE_NON_PERSISTENT = 1;
14
15
	/**
16
	 * @var int
17
	 */
18
	public const DELIVERY_MODE_PERSISTENT = 2;
19
20
	/**
21
	 * @var string
22
	 */
23
	public const CONTENT_TYPE_APPLICATION_JSON = 'application/json';
24
25
	/**
26
	 * @return bool|int|PromiseInterface
27
	 */
28
	final public function produce(Channel $channel, $body)
29
	{
30
		return $channel->publish(
31
			$body,
32
			$this->getHeaders(),
33
			$this->getExchangeName(),
34
			$this->getRoutingKey(),
35
			$this->isMandatory(),
36
			$this->isImmediate()
37
		);
38
	}
39
40
	abstract protected function getExchangeName(): string;
41
42
	abstract protected function getRoutingKey(): string;
43
44
	protected function getHeaders(): array
45
	{
46
		return [];
47
	}
48
49
	protected function isMandatory(): bool
50
	{
51
		return false;
52
	}
53
54
	protected function isImmediate(): bool
55
	{
56
		return false;
57
	}
58
}
59