| Conditions | 14 |
| Paths | 60 |
| Total Lines | 47 |
| Code Lines | 24 |
| 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 |
||
| 65 | protected function driverConnect(): bool |
||
| 66 | { |
||
| 67 | $this->instance = new MemcachedSoftware(); |
||
| 68 | $this->instance->setOption(\Memcached::OPT_BINARY_PROTOCOL, true); |
||
| 69 | $servers = $this->getConfig()->getServers(); |
||
| 70 | |||
| 71 | if (\count($servers) < 1) { |
||
| 72 | $servers = [ |
||
| 73 | [ |
||
| 74 | 'host' => $this->getConfig()->getHost(), |
||
| 75 | 'path' => $this->getConfig()->getPath(), |
||
| 76 | 'port' => $this->getConfig()->getPort(), |
||
| 77 | 'saslUser' => $this->getConfig()->getSaslUser() ?: false, |
||
| 78 | 'saslPassword' => $this->getConfig()->getSaslPassword() ?: false, |
||
| 79 | ], |
||
| 80 | ]; |
||
| 81 | } |
||
| 82 | |||
| 83 | foreach ($servers as $server) { |
||
| 84 | try { |
||
| 85 | /** |
||
| 86 | * If path is provided we consider it as an UNIX Socket |
||
| 87 | */ |
||
| 88 | if(!empty($server[ 'path' ]) && !$this->instance->addServer($server[ 'path' ], 0)){ |
||
| 89 | $this->fallback = true; |
||
| 90 | }else if (!empty($server[ 'host' ]) && !$this->instance->addServer($server[ 'host' ], $server[ 'port' ])) { |
||
| 91 | $this->fallback = true; |
||
| 92 | } |
||
| 93 | |||
| 94 | if (!empty($server[ 'saslUser' ]) && !empty($server[ 'saslPassword' ])) { |
||
| 95 | $this->instance->setSaslAuthData($server[ 'saslUser' ], $server[ 'saslPassword' ]); |
||
|
|
|||
| 96 | } |
||
| 97 | |||
| 98 | } catch (\Exception $e) { |
||
| 99 | $this->fallback = true; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Since Memcached does not throw |
||
| 105 | * any error if not connected ... |
||
| 106 | */ |
||
| 107 | $version = $this->instance->getVersion(); |
||
| 108 | if(!$version || $this->instance->getResultCode() !== MemcachedSoftware::RES_SUCCESS){ |
||
| 109 | throw new PhpfastcacheDriverException('Memcached seems to not be connected'); |
||
| 110 | } |
||
| 111 | return true; |
||
| 112 | } |
||
| 203 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.