Producer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 8
c 1
b 0
f 1
dl 0
loc 29
rs 10
ccs 0
cts 9
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A produce() 0 11 2
1
<?php declare(strict_types = 1);
2
3
namespace Portiny\RabbitMQ\Producer;
4
5
use Bunny\Channel;
6
use Portiny\RabbitMQ\BunnyManager;
7
use React\Promise\PromiseInterface;
8
9
final class Producer
10
{
11
	/**
12
	 * @var BunnyManager
13
	 */
14
	private $bunnyManager;
15
16
17
	public function __construct(BunnyManager $bunnyManager)
18
	{
19
		$this->bunnyManager = $bunnyManager;
20
	}
21
22
23
	/**
24
	 * @param mixed $body
25
	 * @return bool|int|PromiseInterface
26
	 */
27
	public function produce(AbstractProducer $abstractProducer, $body)
28
	{
29
		$channel = $this->bunnyManager->getChannel();
30
31
		if ($channel instanceof PromiseInterface) {
32
			return $channel->then(function (Channel $channel) use ($abstractProducer, $body) {
33
				return $abstractProducer->produce($channel, $body);
34
			});
35
		}
36
37
		return $abstractProducer->produce($channel, $body);
38
	}
39
40
}
41