Conditions | 5 |
Paths | 6 |
Total Lines | 59 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Tests | 5 |
CRAP Score | 6.3183 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
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 |
||
29 | public function __construct( |
||
30 | $host, |
||
31 | $port, |
||
32 | $user, |
||
33 | $password, |
||
34 | $vhost = '/', |
||
35 | $insist = false, |
||
36 | $login_method = 'AMQPLAIN', |
||
37 | $login_response = null, |
||
38 | $locale = 'en_US', |
||
39 | $connection_timeout = 3.0, |
||
40 | $read_write_timeout = 3.0, |
||
41 | $context = null, |
||
42 | $keepalive = false, |
||
43 | $heartbeat = 0, |
||
44 | $channel_rpc_timeout = 0.0, |
||
45 | $ssl_protocol = null, |
||
46 | ?AMQPConnectionConfig $config = null |
||
47 | 30 | ) { |
|
48 | 1 | if ($ssl_protocol !== null && $ssl_protocol instanceof AMQPConnectionConfig === false) { |
|
49 | trigger_error( |
||
50 | '$ssl_protocol parameter is deprecated, use stream_context_set_option($context, \'ssl\', \'crypto_method\', $ssl_protocol) instead (see https://www.php.net/manual/en/function.stream-socket-enable-crypto.php for possible values)', |
||
51 | 29 | E_USER_DEPRECATED |
|
52 | ); |
||
53 | } elseif ($ssl_protocol instanceof AMQPConnectionConfig) { |
||
54 | $config = $ssl_protocol; |
||
55 | } |
||
56 | |||
57 | if ($channel_rpc_timeout > $read_write_timeout) { |
||
58 | throw new \InvalidArgumentException('channel RPC timeout must not be greater than I/O read-write timeout'); |
||
59 | } |
||
60 | |||
61 | $io = new StreamIO( |
||
62 | 29 | $host, |
|
63 | $port, |
||
64 | $connection_timeout, |
||
65 | $read_write_timeout, |
||
66 | $context, |
||
67 | $keepalive, |
||
68 | $heartbeat |
||
69 | ); |
||
70 | |||
71 | parent::__construct( |
||
72 | $user, |
||
73 | $password, |
||
74 | $vhost, |
||
75 | $insist, |
||
76 | $login_method, |
||
77 | $login_response, |
||
78 | 28 | $locale, |
|
79 | $io, |
||
80 | $heartbeat, |
||
81 | $connection_timeout, |
||
82 | $channel_rpc_timeout, |
||
83 | $config |
||
84 | ); |
||
85 | |||
86 | // save the params for the use of __clone, this will overwrite the parent |
||
87 | $this->construct_params = func_get_args(); |
||
88 | } |
||
135 |