| Conditions | 10 |
| Paths | 48 |
| Total Lines | 36 |
| 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 |
||
| 23 | // config |
||
| 24 | if (isset($config['ttl'])) { |
||
| 25 | $this->ttl = (int) $config['ttl']; |
||
| 26 | } |
||
| 27 | |||
| 28 | $persistentId = null; |
||
| 29 | if (isset($config['connection_persistent']) && $config['connection_persistent']) { |
||
| 30 | $persistentId = '1'; |
||
| 31 | |||
| 32 | if (isset($config['pool_size']) && $config['pool_size'] > 1) { |
||
| 33 | $persistentId = (string) random_int(1, $config['pool_size']); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | $this->memcached = new Memcached($persistentId); |
||
| 38 | $this->memcached->addServers($config['servers']); |
||
| 39 | |||
| 40 | if (isset($config['options']) && !empty($config['options'])) { |
||
| 41 | $this->memcached->setOptions($config['options']); |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($this->namespace) { |
||
| 45 | $this->memcached->setOption(Memcached::OPT_PREFIX_KEY, $this->namespace); |
||
| 46 | } |
||
| 47 | |||
| 48 | if (isset($config['cache_not_found_keys'])) { |
||
| 49 | $this->cacheNotFoundKeys = (bool) $config['cache_not_found_keys']; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return mixed |
||
| 55 | */ |
||
| 56 | public function get(string $key) |
||
| 57 | { |
||
| 58 | $value = $this->memcached->get($key); |
||
| 59 | |||
| 152 |