AbstractProducer::getHeaders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 1
c 2
b 0
f 1
dl 0
loc 3
rs 10
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
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
	public const DELIVERY_MODE_NON_PERSISTENT = 1;
11
12
	public const DELIVERY_MODE_PERSISTENT = 2;
13
14
	public const CONTENT_TYPE_APPLICATION_JSON = 'application/json';
15
16
17
	/**
18
	 * @param mixed $body
19
	 * @return bool|int|PromiseInterface
20
	 */
21
	final public function produce(Channel $channel, $body)
22
	{
23
		return $channel->publish(
24
			$body,
25
			$this->getHeaders(),
26
			$this->getExchangeName(),
27
			$this->getRoutingKey(),
28
			$this->isMandatory(),
29
			$this->isImmediate()
30
		);
31
	}
32
33
34
	abstract protected function getExchangeName(): string;
35
36
37
	abstract protected function getRoutingKey(): string;
38
39
40
	protected function getHeaders(): array
41
	{
42
		return [];
43
	}
44
45
46
	protected function isMandatory(): bool
47
	{
48
		return false;
49
	}
50
51
52
	protected function isImmediate(): bool
53
	{
54
		return false;
55
	}
56
57
}
58