AMQPSSLConnection   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 85%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 29
c 5
b 0
f 0
dl 0
loc 74
ccs 17
cts 20
cp 0.85
rs 10
wmc 15

3 Methods

Rating   Name   Duplication   Size   Complexity  
A try_create_connection() 0 4 2
B __construct() 0 34 11
A createSslContext() 0 10 2
1
<?php
2
3
namespace PhpAmqpLib\Connection;
4
5
class AMQPSSLConnection extends AMQPStreamConnection
6
{
7
    /**
8
     * @param string $host
9
     * @param int $port
10
     * @param string $user
11
     * @param string $password
12
     * @param string $vhost
13
     * @param array $ssl_options
14
     * @param array $options
15
     * @param AMQPConnectionConfig|null $config
16
     * @throws \Exception
17
     */
18 3
    public function __construct(
19
        $host,
20
        $port,
21
        $user,
22
        $password,
23
        $vhost = '/',
24
        $ssl_options = array(),
25
        $options = array(),
26
        ?AMQPConnectionConfig $config = null
27
    ) {
28
        if (empty($ssl_options)) {
29 3
            trigger_error('Using non-TLS instances of AMQPSSLConnection is deprecated and will be removed in version 4 of php-amqplib', E_USER_DEPRECATED);
30 3
            $ssl_context = null;
31
        } else {
32
            $ssl_context = $this->createSslContext($ssl_options);
33
        }
34
35
        parent::__construct(
0 ignored issues
show
Deprecated Code introduced by
The function PhpAmqpLib\Connection\AM...nnection::__construct() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

35
        /** @scrutinizer ignore-deprecated */ parent::__construct(
Loading history...
36 3
            $host,
37 3
            $port,
38 3
            $user,
39 3
            $password,
40 3
            $vhost,
41 3
            isset($options['insist']) ? $options['insist'] : false,
42
            isset($options['login_method']) ? $options['login_method'] : 'AMQPLAIN',
43 3
            isset($options['login_response']) ? $options['login_response'] : null,
44 3
            isset($options['locale']) ? $options['locale'] : 'en_US',
45 3
            isset($options['connection_timeout']) ? $options['connection_timeout'] : 3,
46
            isset($options['read_write_timeout']) ? $options['read_write_timeout'] : 130,
47
            $ssl_context,
48
            isset($options['keepalive']) ? $options['keepalive'] : false,
49
            isset($options['heartbeat']) ? $options['heartbeat'] : 0,
50
            isset($options['channel_rpc_timeout']) ? $options['channel_rpc_timeout'] : 0.0,
51
            $config
52
        );
53
    }
54
55
    /**
56
     * @deprecated Use AmqpConnectionFactory
57
     * @throws \Exception
58
     */
59
    public static function try_create_connection($host, $port, $user, $password, $vhost, $options)
60
    {
61
        $ssl_options = isset($options['ssl_options']) ? $options['ssl_options'] : [];
62
        return new static($host, $port, $user, $password, $vhost, $ssl_options, $options);
63
    }
64 3
65
    /**
66 3
     * @param array $options
67 3
     * @return resource
68 3
     */
69
    private function createSslContext($options)
70
    {
71 3
        $ssl_context = stream_context_create();
72
        foreach ($options as $k => $v) {
73
            // Note: 'ssl' applies to 'tls' as well
74
            // https://www.php.net/manual/en/context.ssl.php
75
            stream_context_set_option($ssl_context, 'ssl', $k, $v);
76
        }
77
78
        return $ssl_context;
79
    }
80
}
81