Passed
Push — master ( c65021...b58a23 )
by Murilo
02:50
created

RabbitSender::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 7
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Source\Infra\Queue\RabbitMQ;
6
7
// RabbitMQ MessageType lib. (The buffer class)
8
use PhpAmqpLib\Message\AMQPMessage;
0 ignored issues
show
Bug introduced by
The type PhpAmqpLib\Message\AMQPMessage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Send a message to queue
12
 *
13
 * @version 0.1.0
14
 * @author Murilo Chianfa <github.com/MuriloChianfa>
15
 * @package Source\Infra\Queue\RabbitMQ\RabbitSender
16
 */
17
final class RabbitSender extends RabbitMQ
18
{
19
    /**
20
     * @param string $queue
21
     * @param string $exchanger
22
     */
23
    public function __construct(string $queue, string $exchanger)
24
    {
25
        // basic validation for the queue, valid by the trait
26
        $this->setQueue($queue);
27
28
        // basic validation for the exchanger, valid by the trait
29
        $this->setExchanger($exchanger);
30
    }
31
32
    /**
33
     * The sender will be send your text message to queue
34
     *
35
     * @param string $message The message you will send
36
     * @return void
37
     */
38
    public function sendMessage(string $message): void
39
    {
40
        $message = str_replace("\n", '<br>', $message);
41
42
        $Buffer = new AMQPMessage($message, [
43
            'content_type' => 'text/plain',
44
            'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT
45
        ]);
46
47
        $this->getInstance(
48
            $this->getQueue(),
49
            $this->getExchanger()
50
        )->channel->basic_publish($Buffer, $this->getExchanger());
51
        $this->closeConnection();
52
    }
53
}
54