Connection::getStream()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 18
cts 18
cp 1
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Ccovey\RabbitMQ\Connection;
4
5
use Ccovey\RabbitMQ\Channel;
6
use Ccovey\RabbitMQ\ChannelInterface;
7
use PhpAmqpLib\Connection\AMQPStreamConnection;
8
9
class Connection implements ConnectionInterface
10
{
11
    /**
12
     * @var ConnectionParameters
13
     */
14
    private $parameters;
15
16
    /**
17
     * @var AMQPStreamConnection
18
     */
19
    private $stream;
20
21 3
    public function __construct(ConnectionParameters $parameters)
22
    {
23 3
        $this->parameters = $parameters;
24 3
    }
25
26 1
    public function connect()
27
    {
28 1
        $this->getStream()->reconnect();
29 1
    }
30
31 2
    public function getChannel(string $channelId = '') : ChannelInterface
32
    {
33 2
        return new Channel($this->getStream()->channel($channelId));
34
    }
35
36 1
    protected function getStream()
37
    {
38 1
        if (!$this->stream) {
39 1
            $this->stream = new AMQPStreamConnection(
40 1
                $this->parameters->getHost(),
41 1
                $this->parameters->getPort(),
42 1
                $this->parameters->getUser(),
43 1
                $this->parameters->getPassword(),
44 1
                $this->parameters->getVhost(),
45 1
                $this->parameters->shouldInsist(),
46 1
                $this->parameters->getLoginMethod(),
47 1
                $this->parameters->getLoginResponse(),
48 1
                $this->parameters->getLocale(),
49 1
                $this->parameters->getConnectionTimeout(),
50 1
                $this->parameters->getReadWriteTimeout(),
51 1
                $this->parameters->getContext(),
52 1
                $this->parameters->shouldKeepalive(),
53 1
                $this->parameters->getHeartbeat()
54
            );
55
        }
56
57 1
        return $this->stream;
58
    }
59
}
60