| Conditions | 23 |
| Paths | 9 |
| Total Lines | 34 |
| Code Lines | 18 |
| 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 |
||
| 120 | public function setServers(array $servers): static |
||
| 121 | { |
||
| 122 | $this->enforceLockedProperty(__FUNCTION__); |
||
| 123 | foreach ($servers as $server) { |
||
| 124 | if ($diff = array_diff(array_keys($server), ['host', 'port', 'saslUser', 'saslPassword', 'path'])) { |
||
| 125 | throw new PhpfastcacheInvalidConfigurationException('Unknown keys for memcached server: ' . implode(', ', $diff)); |
||
| 126 | } |
||
| 127 | |||
| 128 | if (!empty($server['host']) && !empty($server['path'])) { |
||
| 129 | throw new PhpfastcacheInvalidConfigurationException('Host and path cannot be simultaneous defined.'); |
||
| 130 | } |
||
| 131 | |||
| 132 | if ((isset($server['host']) && !is_string($server['host'])) || (empty($server['path']) && empty($server['host']))) { |
||
| 133 | throw new PhpfastcacheInvalidConfigurationException('Host must be a valid string in "$server" configuration array if path is not defined'); |
||
| 134 | } |
||
| 135 | |||
| 136 | if ((isset($server['path']) && !is_string($server['path'])) || (empty($server['host']) && empty($server['path']))) { |
||
| 137 | throw new PhpfastcacheInvalidConfigurationException('Path must be a valid string in "$server" configuration array if host is not defined'); |
||
| 138 | } |
||
| 139 | |||
| 140 | if (!empty($server['host']) && (empty($server['port']) || !is_int($server['port'])|| $server['port'] < 1)) { |
||
| 141 | throw new PhpfastcacheInvalidConfigurationException('Port must be a valid integer in "$server" configuration array'); |
||
| 142 | } |
||
| 143 | |||
| 144 | if (!empty($server['port']) && !empty($server['path'])) { |
||
| 145 | throw new PhpfastcacheInvalidConfigurationException('Port should not be defined along with path'); |
||
| 146 | } |
||
| 147 | |||
| 148 | if (!empty($server['saslUser']) && !empty($server['saslPassword']) && (!is_string($server['saslUser']) || !is_string($server['saslPassword']))) { |
||
| 149 | throw new PhpfastcacheInvalidConfigurationException('If provided, saslUser and saslPassword must be a string'); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | $this->servers = $servers; |
||
| 153 | return $this; |
||
| 154 | } |
||
| 218 |