Completed
Push — master ( 2a2905...08a817 )
by
unknown
11s
created

AMQPSocketConnection::try_create_connection()   F

Complexity

Conditions 9
Paths 256

Size

Total Lines 31
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 30
cp 0
rs 3
c 0
b 0
f 0
cc 9
eloc 30
nc 256
nop 6
crap 90
1
<?php
2
namespace PhpAmqpLib\Connection;
3
4
use PhpAmqpLib\Wire\IO\SocketIO;
5
6
class AMQPSocketConnection extends AbstractConnection
7
{
8
    /**
9
     * @param string $host
10
     * @param int $port
11
     * @param string $user
12
     * @param string $password
13
     * @param string $vhost
14
     * @param bool $insist
15
     * @param string $login_method
16
     * @param null $login_response
17
     * @param string $locale
18
     * @param float $read_timeout
19
     * @param bool $keepalive
20
     * @param int $write_timeout
21
     * @param int $heartbeat
22
     */
23 54
    public function __construct(
24
        $host,
25
        $port,
26
        $user,
27
        $password,
28
        $vhost = '/',
29
        $insist = false,
30
        $login_method = 'AMQPLAIN',
31
        $login_response = null,
32
        $locale = 'en_US',
33
        $read_timeout = 3,
34
        $keepalive = false,
35
        $write_timeout = 3,
36
        $heartbeat = 0
37
    ) {
38 54
        $io = new SocketIO($host, $port, $read_timeout, $keepalive, $write_timeout, $heartbeat);
39
40 54
        parent::__construct(
41 54
            $user,
42 54
            $password,
43 54
            $vhost,
44 54
            $insist,
45 54
            $login_method,
46 54
            $login_response,
47 54
            $locale,
48 54
            $io,
49 18
            $heartbeat
50 36
        );
51 54
    }
52
53
    protected static function try_create_connection($host, $port, $user, $password, $vhost, $options){
54
        $insist = isset($options['insist']) ?
55
                        $options['insist'] : false;
56
        $login_method = isset($options['login_method']) ?
57
                              $options['login_method'] :'AMQPLAIN';
58
        $login_response = isset($options['login_response']) ?
59
                                $options['login_response'] : null;
60
        $locale = isset($options['locale']) ?
61
                        $options['locale'] : 'en_US';
62
        $read_timeout = isset($options['read_timeout']) ?
63
                              $options['read_timeout'] : 3;
64
        $keepalive = isset($options['keepalive']) ?
65
                           $options['keepalive'] : false;
66
        $write_timeout = isset($options['write_timeout']) ?
67
                               $options['write_timeout'] : 3;
68
        $heartbeat = isset($options['heartbeat']) ?
69
                           $options['heartbeat'] : 0;
70
        return new static($host,
71
                          $port,
72
                          $user,
73
                          $password,
74
                          $vhost,
75
                          $insist,
76
                          $login_method,
77
                          $login_response,
78
                          $locale,
79
                          $read_timeout,
80
                          $keepalive,
81
                          $write_timeout,
82
                          $heartbeat);
83
    }
84
}
85