AMQPStreamConnection::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 41
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1

Importance

Changes 7
Bugs 2 Features 1
Metric Value
c 7
b 2
f 1
dl 0
loc 41
ccs 21
cts 21
cp 1
rs 8.8571
cc 1
eloc 34
nc 1
nop 14
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
namespace PhpAmqpLib\Connection;
3
4
use PhpAmqpLib\Wire\IO\StreamIO;
5
6
class AMQPStreamConnection extends AbstractConnection
7
{
8
    /**
9
     * @param string $host
10
     * @param string $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 int $connection_timeout
19
     * @param int $read_write_timeout
20
     * @param null $context
21
     * @param bool $keepalive
22
     * @param int $heartbeat
23
     */
24 40
    public function __construct(
25
        $host,
26
        $port,
27
        $user,
28
        $password,
29
        $vhost = '/',
30
        $insist = false,
31
        $login_method = 'AMQPLAIN',
32
        $login_response = null,
33
        $locale = 'en_US',
34
        $connection_timeout = 3,
35
        $read_write_timeout = 3,
36
        $context = null,
37
        $keepalive = false,
38
        $heartbeat = 0
39
    ) {
40 40
        $io = new StreamIO(
41 32
            $host,
42 32
            $port,
43 32
            $connection_timeout,
44 32
            $read_write_timeout,
45 32
            $context,
46 32
            $keepalive,
47
            $heartbeat
48 32
        );
49
50 40
        parent::__construct(
51 32
            $user,
52 32
            $password,
53 32
            $vhost,
54 32
            $insist,
55 32
            $login_method,
56 32
            $login_response,
57 32
            $locale,
58 32
            $io,
59
            $heartbeat
60 32
        );
61
62
        // save the params for the use of __clone, this will overwrite the parent
63 40
        $this->construct_params = func_get_args();
64 40
    }
65
}
66