From 63b9b974a3286fbaf430b9c6f2343c53f8309167 Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 4 Jan 2024 13:44:31 +0800 Subject: [PATCH] Restore PSR-16 Simple Cache v1 compatibility --- .../Collection/Memory/SimpleCache1.php | 30 +++++-------------- .../Collection/Memory/SimpleCache3.php | 26 ++++------------ 2 files changed, 13 insertions(+), 43 deletions(-) diff --git a/src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php b/src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php index a49361ded8..b8918c9153 100644 --- a/src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php +++ b/src/PhpSpreadsheet/Collection/Memory/SimpleCache1.php @@ -2,13 +2,12 @@ namespace PhpOffice\PhpSpreadsheet\Collection\Memory; -use DateInterval; use Psr\SimpleCache\CacheInterface; /** * This is the default implementation for in-memory cell collection. * - * Alternatives implementation should leverage off-memory, non-volatile storage + * Alternative implementation should leverage off-memory, non-volatile storage * to reduce overall memory usage. */ class SimpleCache1 implements CacheInterface @@ -25,14 +24,14 @@ public function clear(): bool return true; } - public function delete(string $key): bool + public function delete($key): bool { unset($this->cache[$key]); return true; } - public function deleteMultiple(iterable $keys): bool + public function deleteMultiple($keys): bool { foreach ($keys as $key) { $this->delete($key); @@ -41,10 +40,7 @@ public function deleteMultiple(iterable $keys): bool return true; } - /** - * @param mixed $default - */ - public function get(string $key, $default = null): mixed + public function get($key, $default = null): mixed { if ($this->has($key)) { return $this->cache[$key]; @@ -53,10 +49,7 @@ public function get(string $key, $default = null): mixed return $default; } - /** - * @param mixed $default - */ - public function getMultiple(iterable $keys, $default = null): iterable + public function getMultiple($keys, $default = null): iterable { $results = []; foreach ($keys as $key) { @@ -66,26 +59,19 @@ public function getMultiple(iterable $keys, $default = null): iterable return $results; } - public function has(string $key): bool + public function has($key): bool { return array_key_exists($key, $this->cache); } - /** - * @param mixed $value - * @param null|DateInterval|int $ttl - */ - public function set(string $key, $value, $ttl = null): bool + public function set($key, $value, $ttl = null): bool { $this->cache[$key] = $value; return true; } - /** - * @param null|DateInterval|int $ttl - */ - public function setMultiple(iterable $values, $ttl = null): bool + public function setMultiple($values, $ttl = null): bool { foreach ($values as $key => $value) { $this->set($key, $value); diff --git a/src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php b/src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php index b89ee16b35..7b6c460b94 100644 --- a/src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php +++ b/src/PhpSpreadsheet/Collection/Memory/SimpleCache3.php @@ -8,14 +8,11 @@ /** * This is the default implementation for in-memory cell collection. * - * Alternatives implementation should leverage off-memory, non-volatile storage + * Alternative implementation should leverage off-memory, non-volatile storage * to reduce overall memory usage. */ class SimpleCache3 implements CacheInterface { - /** - * @var array Cell Cache - */ private array $cache = []; public function clear(): bool @@ -41,10 +38,7 @@ public function deleteMultiple(iterable $keys): bool return true; } - /** - * @param mixed $default - */ - public function get(string $key, $default = null): mixed + public function get(string $key, mixed $default = null): mixed { if ($this->has($key)) { return $this->cache[$key]; @@ -53,10 +47,7 @@ public function get(string $key, $default = null): mixed return $default; } - /** - * @param mixed $default - */ - public function getMultiple(iterable $keys, $default = null): iterable + public function getMultiple(iterable $keys, mixed $default = null): iterable { $results = []; foreach ($keys as $key) { @@ -71,21 +62,14 @@ public function has(string $key): bool return array_key_exists($key, $this->cache); } - /** - * @param mixed $value - * @param null|DateInterval|int $ttl - */ - public function set(string $key, $value, $ttl = null): bool + public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool { $this->cache[$key] = $value; return true; } - /** - * @param null|DateInterval|int $ttl - */ - public function setMultiple(iterable $values, $ttl = null): bool + public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool { foreach ($values as $key => $value) { $this->set($key, $value);