diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 6d4c1c1c..38ce05f5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -14,6 +14,7 @@ tests tests/psalm-stubs.php + src/Cache diff --git a/psalm.xml.dist b/psalm.xml.dist index 60328f81..1afe1dd1 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -14,6 +14,7 @@ + diff --git a/src/Cache/DevNullCache.php b/src/Cache/DevNullCache.php index 750a3663..7e71067c 100644 --- a/src/Cache/DevNullCache.php +++ b/src/Cache/DevNullCache.php @@ -4,75 +4,19 @@ namespace Scoutapm\Cache; -use Psr\SimpleCache\CacheInterface; +use Composer\InstalledVersions; -use function array_combine; -use function array_map; -use function is_array; -use function iterator_to_array; - -/** @internal */ -final class DevNullCache implements CacheInterface -{ - /** @inheritDoc */ - public function get($key, $default = null) - { - return $default; - } - - /** @inheritDoc */ - public function set($key, $value, $ttl = null): bool - { - return true; - } - - /** @inheritDoc */ - public function delete($key): bool - { - return true; - } - - public function clear(): bool - { - return true; - } - - /** @inheritDoc */ - public function getMultiple($keys, $default = null) +$simpleCacheVersion = InstalledVersions::getPrettyVersion('psr/simple-cache'); +if (version_compare($simpleCacheVersion, '2.0.0', '<')) { + /** @internal */ + final class DevNullCache extends DevNullCacheSimpleCache1 { - if (is_array($keys)) { - $keysAsArray = $keys; - } else { - $keysAsArray = iterator_to_array($keys, false); - } - - return array_combine( - $keysAsArray, - array_map( - /** @return mixed */ - function (string $key) use ($default) { - return $this->get($key, $default); - }, - $keysAsArray - ) - ); } - /** @inheritDoc */ - public function setMultiple($values, $ttl = null): bool - { - return true; - } - - /** @inheritDoc */ - public function deleteMultiple($keys): bool - { - return true; - } + return; +} - /** @inheritDoc */ - public function has($key): bool - { - return false; - } +/** @internal */ +final class DevNullCache extends DevNullCacheSimpleCache2And3 +{ } diff --git a/src/Cache/DevNullCacheSimpleCache1.php b/src/Cache/DevNullCacheSimpleCache1.php new file mode 100644 index 00000000..68e3ed26 --- /dev/null +++ b/src/Cache/DevNullCacheSimpleCache1.php @@ -0,0 +1,78 @@ +get($key, $default); + }, + $keysAsArray + ) + ); + } + + /** @inheritDoc */ + public function setMultiple($values, $ttl = null): bool + { + return true; + } + + /** @inheritDoc */ + public function deleteMultiple($keys): bool + { + return true; + } + + /** @inheritDoc */ + public function has($key): bool + { + return false; + } +} diff --git a/src/Cache/DevNullCacheSimpleCache2And3.php b/src/Cache/DevNullCacheSimpleCache2And3.php new file mode 100644 index 00000000..3aa60155 --- /dev/null +++ b/src/Cache/DevNullCacheSimpleCache2And3.php @@ -0,0 +1,79 @@ +get($key, $default); + }, + $keysAsArray + ) + ); + } + + /** @inheritDoc */ + public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool + { + return true; + } + + /** @inheritDoc */ + public function deleteMultiple(iterable $keys): bool + { + return true; + } + + /** @inheritDoc */ + public function has(string $key): bool + { + return false; + } +}