Rabbit::__destruct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Source\Core\Rabbit;
4
5
use PhpAmqpLib\Connection\AMQPStreamConnection;
0 ignored issues
show
Bug introduced by
The type PhpAmqpLib\Connection\AMQPStreamConnection 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...
6
use PhpAmqpLib\Exchange\AMQPExchangeType;
0 ignored issues
show
Bug introduced by
The type PhpAmqpLib\Exchange\AMQPExchangeType 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...
7
8
abstract class Rabbit implements RabbitInterface
9
{
10
    use RabbitTrait;
11
12
    /**
13
     * @var string $host
14
     */
15
    const HOST = CONF_RABBITMQ_HOST;
16
17
    /**
18
     * @var int $port
19
     */
20
    const PORT = CONF_RABBITMQ_PORT;
21
22
    /**
23
     * @var string $user
24
     */
25
    const USER = CONF_RABBITMQ_USER;
26
27
    /**
28
     * @var string $passwd
29
     */
30
    const PASSWD = CONF_RABBITMQ_PASS;
31
32
    /**
33
     * @var AMQPStreamConnection $connection
34
     */
35
    protected $connection;
36
37
    /**
38
     * @var object $channel
39
     */
40
    protected $channel;
41
42
    /**
43
     * Declare the queue and exchanger of the your rabbitmq server
44
     * @var string $queue
45
     * @var string $exchanger
46
     * @return self
47
     */
48
    protected function getInstance(string $queue, string $exchanger, bool $reply = false): self
49
    {
50
        // basic validation for the queue, valid by the trait
51
        $this->setQueue($queue);
52
53
        // basic validation for the exchanger, valid by the trait
54
        $this->setExchanger($exchanger);
55
56
        // basic validation for the reply, valid by the trait
57
        $this->setReply($reply);
58
59
        $this->connection = new AMQPStreamConnection(self::HOST, self::PORT, self::USER, self::PASSWD);
60
        $this->channel = $this->connection->channel();
61
62
        $this->channel->queue_declare($this->queue, true, false, false, false);
63
        $this->channel->exchange_declare($this->exchanger, AMQPExchangeType::DIRECT, false, true, false);
64
        $this->channel->queue_bind($this->queue, $this->exchanger);
65
66
        $this->channel->basic_qos(null, 1, null);
67
        return $this;
68
    }
69
70
    /**
71
     * Close the connection with the rabbitmq
72
     */
73
    protected function closeConnection()
74
    {
75
        if (!empty($this->channel)) {
76
            $this->channel->close();
77
        }
78
79
        if (!empty($this->connection)) {
80
            $this->connection->close();
81
        }
82
    }
83
84
    /**
85
     * Close the connection with the rabbitmq
86
     */
87
    public function __destruct()
88
    {
89
        $this->closeConnection();
90
    }
91
}
92