Skip to content
Snippets Groups Projects
Commit 4ba90617 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Fix Psalm-issues in Memcache.php

parent d8dff112
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,8 @@
namespace SimpleSAML;
use Memcache as _Memcache;
use Memcached as _Memcached;
use SimpleSAML\Utils;
/**
......@@ -26,7 +28,7 @@ class Memcache
/**
* Cache of the memcache servers we are using.
*
* @var \Memcache[]|null
* @var \Memcache[]|\Memcached[]|null
*/
private static $serverGroups = null;
......@@ -212,7 +214,7 @@ class Memcache
* The timeout for contacting this server, in seconds.
* The default value is 3 seconds.
*
* @param \Memcache $memcache The Memcache object we should add this server to.
* @param \Memcache|\Memcached $memcache The Memcache object we should add this server to.
* @param array $server An associative array with the configuration options for the server to add.
* @return void
*
......@@ -290,7 +292,7 @@ class Memcache
}
// add this server to the Memcache object
if (self::$extension === '\memcached') {
if ($memcache instanceof \Memcached) {
$memcache->addServer($hostname, $port);
} else {
$memcache->addServer($hostname, $port, true, $weight, $timeout, $timeout, true);
......@@ -304,24 +306,25 @@ class Memcache
*
* @param array $group Array of servers which should be created as a group.
*
* @return \Memcache A Memcache object of the servers in the group
* @return \Memcache|\Memcached A Memcache object of the servers in the group
*
* @throws \Exception If the servers configuration is invalid.
*/
private static function loadMemcacheServerGroup(array $group)
{
$class = class_exists('\Memcache') ? '\Memcache' : (class_exists('\Memcached') ? '\Memcached' : false);
if (!$class) {
if (class_exists(_Memcache::class)) {
$memcache = new _Memcache();
self::$extension = strtolower(_Memcache::class);
} elseif (class_exists(_Memcached::class)) {
$memcache = new _Memcached();
self::$extension = strtolower(_Memcached::class);
} else {
throw new \Exception(
'Missing Memcached implementation. You must install either the Memcache or Memcached extension.'
);
} elseif (strtolower($class) === '\memcache') {
Logger::warning("The use of PHP-extension memcache is deprecated. Please migrate to the memcached extension.");
}
self::$extension = strtolower($class);
// create the \Memcache object
$memcache = new $class();
// iterate over all the servers in the group and add them to the Memcache object
foreach ($group as $index => $server) {
......@@ -346,6 +349,7 @@ class Memcache
self::addMemcacheServer($memcache, $server);
}
/** @var \Memcache|\Memcached */
return $memcache;
}
......@@ -354,7 +358,7 @@ class Memcache
* This function gets a list of all configured memcache servers. This list is initialized based
* on the content of 'memcache_store.servers' in the configuration.
*
* @return \Memcache[] Array with Memcache objects.
* @return \Memcache[]|\Memcached[] Array with Memcache objects.
*
* @throws \Exception If the servers configuration is invalid.
*/
......
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