Browse Source

Apply suggestions from code review

Co-authored-by: othercorey <corey.taylor.fl@gmail.com>
Mark Story 5 years ago
parent
commit
09f79790b7
1 changed files with 8 additions and 13 deletions
  1. 8 13
      src/Cache/Engine/MemcachedEngine.php

+ 8 - 13
src/Cache/Engine/MemcachedEngine.php

@@ -146,21 +146,16 @@ class MemcachedEngine extends CacheEngine
         $this->_setOptions();
 
         $serverList = $this->_Memcached->getServerList();
-        if (count($serverList)) {
+        if ($serverList) {
             if ($this->_config['persistent'] !== false) {
-                $actualServers = [];
                 foreach ($serverList as $server) {
-                    $actualServers[] = $server['host'] . ':' . $server['port'];
-                }
-                unset($server);
-                sort($actualServers);
-                $configuredServers = $this->_config['servers'];
-                sort($configuredServers);
-                if ($actualServers !== $configuredServers) {
-                    $message = 'Invalid cache configuration. Multiple persistent cache configurations are detected' .
-                        ' with different `servers` values. `servers` values for persistent cache configurations' .
-                        ' must be the same when using the same persistence id.';
-                    throw new InvalidArgumentException($message);
+                    if (!in_array($server['host'] . ':' . $server['port'], $this->_config['server'], true)) {
+                        throw new InvalidArgumentException(
+                            'Invalid cache configuration. Multiple persistent cache configurations are detected' .
+                            ' with different `servers` values. `servers` values for persistent cache configurations' .
+                            ' must be the same when using the same persistence id.'
+                        );
+                    }
                 }
             }