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