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