| Conditions | 20 |
| Paths | 3036 |
| Total Lines | 44 |
| Code Lines | 22 |
| 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 |
||
| 70 | protected function driverConnect(): bool |
||
| 71 | { |
||
| 72 | $this->instance = new MemcacheSoftware(); |
||
| 73 | $servers = (!empty($this->config->getOption('servers')) && \is_array($this->config->getOption('servers')) ? $this->config->getOption('servers') : []); |
||
| 74 | if (\count($servers) < 1) { |
||
| 75 | $servers = [ |
||
| 76 | [ |
||
| 77 | 'host' => !empty($this->config->getOption('host')) ? $this->config->getOption('host') : '127.0.0.1', |
||
| 78 | 'path' => !empty($this->config->getOption('path')) ? $this->config->getOption('path') : false, |
||
| 79 | 'port' => !empty($this->config->getOption('port')) ? $this->config->getOption('port') : 11211, |
||
| 80 | 'saslUser' => !empty($this->config->getOption('saslUser')) ? $this->config->getOption('saslUser') : false, |
||
| 81 | 'saslPassword' =>!empty($this->config->getOption('saslPassword')) ? $this->config->getOption('saslPassword'): false, |
||
| 82 | ], |
||
| 83 | ]; |
||
| 84 | } |
||
| 85 | |||
| 86 | foreach ($servers as $server) { |
||
| 87 | try { |
||
| 88 | /** |
||
| 89 | * If path is provided we consider it as an UNIX Socket |
||
| 90 | */ |
||
| 91 | if(!empty($server[ 'path' ]) && !$this->instance->addServer($server[ 'path' ], 0)){ |
||
| 92 | $this->fallback = true; |
||
| 93 | }else if (!empty($server[ 'host' ]) && !$this->instance->addServer($server[ 'host' ], $server[ 'port' ])) { |
||
| 94 | $this->fallback = true; |
||
| 95 | } |
||
| 96 | |||
| 97 | if (!empty($server[ 'saslUser' ]) && !empty($server[ 'saslPassword' ])) { |
||
| 98 | throw new phpFastCacheDriverException('Unlike Memcached, Memcache does not support SASL authentication'); |
||
| 99 | } |
||
| 100 | } catch (\Exception $e) { |
||
| 101 | $this->fallback = true; |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Since Memcached does not throw |
||
| 106 | * any error if not connected ... |
||
| 107 | */ |
||
| 108 | if(!$this->instance->getServerStatus(!empty($server[ 'path' ]) ? $server[ 'path' ] : $server[ 'host' ], !empty($server[ 'port' ]) ? $server[ 'port' ] : 0)){ |
||
| 109 | throw new phpFastCacheDriverException('Memcache seems to not be connected'); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return true; |
||
| 114 | } |
||
| 204 | } |