Conditions | 15 |
Paths | 507 |
Total Lines | 64 |
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 |
||
129 | if ($params['connection_persistent']) { |
||
130 | $connectionId = 1; |
||
131 | |||
132 | if ($params['pool_size'] > 1) { |
||
133 | $connectionId = random_int(1, $params['pool_size']); |
||
134 | } |
||
135 | |||
136 | $persistentId = sprintf('%s-%s-%s', $params['port'], $params['database'], $connectionId); |
||
137 | $this->client->pconnect($params['host'], $params['port'], $params['timeout'] ?? 0, $persistentId, $params['retry_interval'] ?? 0); |
||
138 | } else { |
||
139 | $this->client->connect($params['host'], $params['port'], $params['timeout'] ?? 0, null, $params['retry_interval'] ?? 0); |
||
140 | } |
||
141 | |||
142 | if ($params['password']) { |
||
143 | if (!$this->client->auth($params['password'])) { |
||
144 | throw new InvalidConfigurationException(sprintf('Invalid password for phpredis adapter: %s:%s', $params['host'], $params['port'])); |
||
145 | } |
||
146 | } |
||
147 | |||
148 | if ($params['database']) { |
||
149 | $this->client->select($params['database']); |
||
150 | } |
||
151 | |||
152 | if ($params['serializer']) { |
||
153 | switch ($params['serializer']) { |
||
154 | case 'none': |
||
155 | $this->client->setOption(Redis::OPT_SERIALIZER, (string) Redis::SERIALIZER_NONE); |
||
156 | break; |
||
157 | case 'php': |
||
158 | $this->client->setOption(Redis::OPT_SERIALIZER, (string) Redis::SERIALIZER_PHP); |
||
159 | break; |
||
160 | case 'igbinary': |
||
161 | if (!extension_loaded('igbinary')) { |
||
162 | throw new InvalidConfigurationException('Serializer igbinary requires "igbinary" extension. See https://pecl.php.net/package/igbinary'); |
||
163 | } |
||
164 | |||
165 | if (!defined('Redis::SERIALIZER_IGBINARY')) { |
||
166 | throw new InvalidConfigurationException('Serializer igbinary requires run extension compilation using configure with --enable-redis-igbinary'); |
||
167 | } |
||
168 | |||
169 | $this->client->setOption(Redis::OPT_SERIALIZER, (string) Redis::SERIALIZER_IGBINARY); |
||
170 | break; |
||
171 | } |
||
172 | } |
||
173 | |||
174 | $this->client->setOption(Redis::OPT_SCAN, (string) Redis::SCAN_NORETRY); |
||
175 | |||
176 | if (isset($config['ttl'])) { |
||
177 | $this->ttl = $config['ttl']; |
||
178 | } |
||
179 | |||
180 | if (isset($config['cache_not_found_keys'])) { |
||
181 | $this->cacheNotFoundKeys = (bool) $config['cache_not_found_keys']; |
||
182 | } |
||
183 | |||
184 | if (isset($params['read_timeout'])) { |
||
185 | $this->client->setOption(Redis::OPT_READ_TIMEOUT, (string) $params['read_timeout']); |
||
186 | } |
||
187 | |||
188 | return $this->client; |
||
189 | } |
||
190 | |||
191 | protected function getConnectionParameters(array $config): array |
||
192 | { |
||
193 | $connectionParameters = []; |
||
219 |