Producer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\AMQPBundle\Producer;
5
6
use Innmind\AMQPBundle\Producer as ProducerInterface;
7
use Innmind\AMQP\{
8
    Client,
9
    Model\Basic\Publish,
10
    Model\Basic\Message
11
};
12
13
final class Producer implements ProducerInterface
14
{
15
    private $client;
16
    private $exchange;
17
18 2
    public function __construct(
19
        Client $client,
20
        string $exchange
21
    ) {
22 2
        $this->client = $client;
23 2
        $this->exchange = $exchange;
24 2
    }
25
26 2
    public function __invoke(Message $message, string $routingKey = null): ProducerInterface
27
    {
28
        $this
29 2
            ->client
30 2
            ->channel()
31 2
            ->basic()
32 2
            ->publish(
33 2
                (new Publish($message))
34 2
                    ->to($this->exchange)
35 2
                    ->withRoutingKey($routingKey ?? '')
36
            );
37
38 2
        return $this;
39
    }
40
}
41