From 244df0764fe6475bf416a919ccc58baecb7475f6 Mon Sep 17 00:00:00 2001 From: Kamisama Date: Tue, 27 Aug 2013 14:22:45 -0400 Subject: [PATCH] Coding standard and readability --- lib/Cake/Cache/Engine/MemcachedEngine.php | 48 +++++++++++-------- .../Case/Cache/Engine/MemcachedEngineTest.php | 4 +- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/Cake/Cache/Engine/MemcachedEngine.php b/lib/Cake/Cache/Engine/MemcachedEngine.php index 6b5dd738f..3538becb3 100755 --- a/lib/Cake/Cache/Engine/MemcachedEngine.php +++ b/lib/Cake/Cache/Engine/MemcachedEngine.php @@ -59,6 +59,7 @@ class MemcachedEngine extends CacheEngine { * * @param array $settings array of setting for the engine * @return boolean True if the engine has been successfully initialized, false if not + * @throws CacheException when you try use authentication without Memcached compiled with SASL support */ public function init($settings = array()) { if (!class_exists('Memcached')) { @@ -81,29 +82,34 @@ class MemcachedEngine extends CacheEngine { if (!is_array($this->settings['servers'])) { $this->settings['servers'] = array($this->settings['servers']); } - if (!isset($this->_Memcached)) { - $this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null); - $this->_setOptions(); - if (!count($this->_Memcached->getServerList())) { - $servers = array(); - foreach ($this->settings['servers'] as $server) { - $servers[] = $this->_parseServerString($server); - } + if (isset($this->_Memcached)) { + return true; + } - if (!$this->_Memcached->addServers($servers)) { - return false; - } + $this->_Memcached = new Memcached($this->settings['persistent'] ? $this->settings['persistent_id'] : null); + $this->_setOptions(); - if ($this->settings['login'] !== null && $this->settings['password'] !== null) { - if (!method_exists($this->_Memcached, 'setSaslAuthData')) { - throw new CacheException( - __d('cake_dev', 'Memcached extension is not build with SASL support') - ); - } - $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']); - } + if (count($this->_Memcached->getServerList())) { + return true; + } + + $servers = array(); + foreach ($this->settings['servers'] as $server) { + $servers[] = $this->_parseServerString($server); + } + + if (!$this->_Memcached->addServers($servers)) { + return false; + } + + if ($this->settings['login'] !== null && $this->settings['password'] !== null) { + if (!method_exists($this->_Memcached, 'setSaslAuthData')) { + throw new CacheException( + __d('cake_dev', 'Memcached extension is not build with SASL support') + ); } + $this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']); } return true; @@ -136,10 +142,10 @@ class MemcachedEngine extends CacheEngine { * @return array Array containing host, port */ protected function _parseServerString($server) { - if ($server[0] == 'u') { + if ($server[0] === 'u') { return array($server, 0); } - if (substr($server, 0, 1) == '[') { + if (substr($server, 0, 1) === '[') { $position = strpos($server, ']:'); if ($position !== false) { $position++; diff --git a/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php b/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php index 73741dabc..cc8b61495 100755 --- a/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php +++ b/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php @@ -155,8 +155,8 @@ class MemcachedEngineTest extends CakeTestCase { ); $this->setExpectedException( - 'CacheException', 'Memcached extension is not build with SASL support' - ); + 'CacheException', 'Memcached extension is not build with SASL support' + ); $Memcached->init($settings); }