Conditions | 22 |
Paths | 12960 |
Total Lines | 80 |
Lines | 0 |
Ratio | 0 % |
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:
1 | <?php |
||
38 | public function __construct(array $config) |
||
39 | { |
||
40 | if (!empty($config['host'])) { |
||
41 | $this->host = (string) $config['host']; |
||
42 | } |
||
43 | |||
44 | if (!empty($config['port'])) { |
||
45 | $this->port = (int) $config['port']; |
||
46 | } else { |
||
47 | $this->port = false; |
||
48 | } |
||
49 | |||
50 | if (!empty($config['username'])) { |
||
51 | $this->username = (string) $config['username']; |
||
52 | } |
||
53 | |||
54 | if (!empty($config['password'])) { |
||
55 | $this->password = (string) $config['password']; |
||
56 | } |
||
57 | |||
58 | if (!empty($config['services']) && is_array($config['services'])) { |
||
59 | $this->services = $config['services']; |
||
60 | |||
61 | if (!empty($config['serviceExtensions']) && is_array($config['serviceExtensions'])) { |
||
62 | $this->serviceExtensions = $config['serviceExtensions']; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | if ((!empty($config['ssl']) && is_bool($config['ssl']))) { |
||
67 | $this->ssl = $config['ssl']; |
||
68 | } else { |
||
69 | $this->ssl = false; |
||
70 | } |
||
71 | |||
72 | if (!empty($config['local_cert'])) { |
||
73 | $this->local_cert = (string) $config['local_cert']; |
||
74 | |||
75 | if (!is_readable($this->local_cert)) { |
||
76 | throw new \Exception(sprintf('unable to read local_cert: %s', $this->local_cert)); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | if (!empty($config['ca_cert'])) { |
||
81 | $this->ca_cert = (string) $config['ca_cert']; |
||
82 | |||
83 | if (!is_readable($this->ca_cert)) { |
||
84 | throw new \Exception(sprintf('unable to read ca_cert: %s', $this->ca_cert)); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if (!empty($config['pk_cert'])) { |
||
89 | $this->pk_cert = (string) $config['pk_cert']; |
||
90 | |||
91 | if (!is_readable($this->pk_cert)) { |
||
92 | throw new \Exception(sprintf('unable to read pk_cert: %s', $this->pk_cert)); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | if (!empty($config['passphrase'])) { |
||
97 | $this->passphrase = (string) $config['passphrase']; |
||
98 | } |
||
99 | |||
100 | if (!empty($config['debug']) && is_bool($config['debug'])) { |
||
101 | $this->debug = $config['debug']; |
||
102 | } else { |
||
103 | $this->debug = false; |
||
104 | } |
||
105 | |||
106 | if (!empty($config['connect_timeout'])) { |
||
107 | $this->connect_timeout = (int) $config['connect_timeout']; |
||
108 | } else { |
||
109 | $this->connect_timeout = 16; |
||
110 | } |
||
111 | |||
112 | if (!empty($config['timeout'])) { |
||
113 | $this->timeout = (int) $config['timeout']; |
||
114 | } else { |
||
115 | $this->timeout = 32; |
||
116 | } |
||
117 | } |
||
118 | |||
170 |