AbstractProducer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
eloc 14
c 2
b 0
f 1
dl 0
loc 47
rs 10
ccs 0
cts 14
cp 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A produce() 0 9 1
A isMandatory() 0 3 1
A getHeaders() 0 3 1
A isImmediate() 0 3 1
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