Skip to content
Snippets Groups Projects
Unverified Commit 332a261b authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Phpdoc & reduced complexity

parent be636755
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ class Memcache ...@@ -24,7 +24,7 @@ class Memcache
/** /**
* Cache of the memcache servers we are using. * Cache of the memcache servers we are using.
* *
* @var Memcache[]|null * @var \Memcache[]|null
*/ */
private static $serverGroups = null; private static $serverGroups = null;
...@@ -46,7 +46,7 @@ class Memcache ...@@ -46,7 +46,7 @@ class Memcache
*/ */
public static function get($key) public static function get($key)
{ {
\SimpleSAML\Logger::debug("loading key $key from memcache"); Logger::debug("loading key $key from memcache");
$latestInfo = null; $latestInfo = null;
$latestTime = 0.0; $latestTime = 0.0;
...@@ -77,19 +77,19 @@ class Memcache ...@@ -77,19 +77,19 @@ class Memcache
* - 'data': The data. * - 'data': The data.
*/ */
if (!is_array($info)) { if (!is_array($info)) {
\SimpleSAML\Logger::warning( Logger::warning(
'Retrieved invalid data from a memcache server. Data was not an array.' 'Retrieved invalid data from a memcache server. Data was not an array.'
); );
continue; continue;
} }
if (!array_key_exists('timestamp', $info)) { if (!array_key_exists('timestamp', $info)) {
\SimpleSAML\Logger::warning( Logger::warning(
'Retrieved invalid data from a memcache server. Missing timestamp.' 'Retrieved invalid data from a memcache server. Missing timestamp.'
); );
continue; continue;
} }
if (!array_key_exists('data', $info)) { if (!array_key_exists('data', $info)) {
\SimpleSAML\Logger::warning( Logger::warning(
'Retrieved invalid data from a memcache server. Missing data.' 'Retrieved invalid data from a memcache server. Missing data.'
); );
continue; continue;
...@@ -122,17 +122,17 @@ class Memcache ...@@ -122,17 +122,17 @@ class Memcache
if ($latestData === null) { if ($latestData === null) {
if ($allDown) { if ($allDown) {
// all servers are down, panic! // all servers are down, panic!
$e = new \SimpleSAML\Error\Error('MEMCACHEDOWN', null, 503); $e = new Error\Error('MEMCACHEDOWN', null, 503);
throw new \SimpleSAML\Error\Exception('All memcache servers are down', 503, $e); throw new Error\Exception('All memcache servers are down', 503, $e);
} }
// we didn't find any data matching the key // we didn't find any data matching the key
\SimpleSAML\Logger::debug("key $key not found in memcache"); Logger::debug("key $key not found in memcache");
return null; return null;
} }
if ($mustUpdate) { if ($mustUpdate) {
// we found data matching the key, but some of the servers need updating // we found data matching the key, but some of the servers need updating
\SimpleSAML\Logger::debug("Memcache servers out of sync for $key, forcing sync"); Logger::debug("Memcache servers out of sync for $key, forcing sync");
self::set($key, $latestData); self::set($key, $latestData);
} }
...@@ -149,7 +149,7 @@ class Memcache ...@@ -149,7 +149,7 @@ class Memcache
*/ */
public static function set($key, $value, $expire = null) public static function set($key, $value, $expire = null)
{ {
\SimpleSAML\Logger::debug("saving key $key to memcache"); Logger::debug("saving key $key to memcache");
$savedInfo = array( $savedInfo = array(
'timestamp' => microtime(true), 'timestamp' => microtime(true),
'data' => $value 'data' => $value
...@@ -180,7 +180,7 @@ class Memcache ...@@ -180,7 +180,7 @@ class Memcache
public static function delete($key) public static function delete($key)
{ {
assert(is_string($key)); assert(is_string($key));
\SimpleSAML\Logger::debug("deleting key $key from memcache"); Logger::debug("deleting key $key from memcache");
// store this object to all groups of memcache servers // store this object to all groups of memcache servers
foreach (self::getMemcacheServers() as $server) { foreach (self::getMemcacheServers() as $server) {
...@@ -231,14 +231,8 @@ class Memcache ...@@ -231,14 +231,8 @@ class Memcache
); );
} }
// check if we are told to use a socket
$socket = false;
if (strpos($hostname, 'unix:///') === 0) {
$socket = true;
}
// check if the user has specified a port number // check if the user has specified a port number
if ($socket) { if (strpos($hostname, 'unix:///') === 0) {
// force port to be 0 for sockets // force port to be 0 for sockets
$port = 0; $port = 0;
} elseif (array_key_exists('port', $server)) { } elseif (array_key_exists('port', $server)) {
...@@ -365,7 +359,7 @@ class Memcache ...@@ -365,7 +359,7 @@ class Memcache
self::$serverGroups = array(); self::$serverGroups = array();
// load the configuration // load the configuration
$config = \SimpleSAML\Configuration::getInstance(); $config = Configuration::getInstance();
$groups = $config->getArray('memcache_store.servers'); $groups = $config->getArray('memcache_store.servers');
...@@ -416,7 +410,7 @@ class Memcache ...@@ -416,7 +410,7 @@ class Memcache
private static function getExpireTime() private static function getExpireTime()
{ {
// get the configuration instance // get the configuration instance
$config = \SimpleSAML\Configuration::getInstance(); $config = Configuration::getInstance();
assert($config instanceof \SimpleSAML\Configuration); assert($config instanceof \SimpleSAML\Configuration);
// get the expire-value from the configuration // get the expire-value from the configuration
...@@ -439,9 +433,7 @@ class Memcache ...@@ -439,9 +433,7 @@ class Memcache
/* The expire option is given as the number of seconds into the future an item should expire. We convert this /* The expire option is given as the number of seconds into the future an item should expire. We convert this
* to an actual timestamp. * to an actual timestamp.
*/ */
$expireTime = time() + $expire; return (time() + $expire);
return $expireTime;
} }
...@@ -464,7 +456,7 @@ class Memcache ...@@ -464,7 +456,7 @@ class Memcache
} }
} }
$stats = \SimpleSAML\Utils\Arrays::transpose($stats); $stats = Utils\Arrays::transpose($stats);
$ret = array_merge_recursive($ret, $stats); $ret = array_merge_recursive($ret, $stats);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment