From 3fdcda09a5077bfe962cbf3635b195011d6f0fd3 Mon Sep 17 00:00:00 2001 From: Joshua Behrens Date: Sat, 20 May 2023 17:25:09 +0200 Subject: [PATCH 1/2] Update CachePsr16 to support psr/simple-cache 3 --- src/voku/cache/CachePsr16.php | 50 +++++------------------------------ 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/src/voku/cache/CachePsr16.php b/src/voku/cache/CachePsr16.php index 2cb162c..2db7396 100644 --- a/src/voku/cache/CachePsr16.php +++ b/src/voku/cache/CachePsr16.php @@ -28,12 +28,8 @@ public function clear(): bool * * @return bool True if the item was successfully removed. False if there was an error. */ - public function delete($key): bool + public function delete(string $key): bool { - if (!\is_string($key)) { - throw new InvalidArgumentException('$key is not a string:' . \print_r($key, true)); - } - return $this->removeItem($key); } @@ -46,16 +42,8 @@ public function delete($key): bool * * @return bool True if the items were successfully removed. False if there was an error. */ - public function deleteMultiple($keys): bool + public function deleteMultiple(iterable $keys): bool { - if ( - !\is_array($keys) - && - !($keys instanceof \Traversable) - ) { - throw new InvalidArgumentException('$keys is not iterable:' . \print_r($keys, true)); - } - $results = []; foreach ((array) $keys as $key) { $results[] = $this->delete($key); @@ -74,7 +62,7 @@ public function deleteMultiple($keys): bool * * @return mixed the value of the item from the cache, or $default in case of cache miss */ - public function get($key, $default = null) + public function get(string $key, mixed $default = null): mixed { if ($this->has($key)) { return $this->getItem($key); @@ -94,16 +82,8 @@ public function get($key, $default = null) * @return iterable A list of key => value pairs. Cache keys that do not exist or are stale will have $default as * value. */ - public function getMultiple($keys, $default = null) + public function getMultiple(iterable $keys, mixed $default = null): iterable { - if ( - !\is_array($keys) - && - !($keys instanceof \Traversable) - ) { - throw new InvalidArgumentException('$keys is not iterable:' . \print_r($keys, true)); - } - $result = []; foreach ((array) $keys as $key) { $result[$key] = $this->has($key) ? $this->get($key) : $default; @@ -126,12 +106,8 @@ public function getMultiple($keys, $default = null) * * @return bool */ - public function has($key): bool + public function has(string $key): bool { - if (!\is_string($key)) { - throw new InvalidArgumentException('$key is not a string:' . \print_r($key, true)); - } - return $this->existsItem($key); } @@ -148,12 +124,8 @@ public function has($key): bool * * @return bool true on success and false on failure */ - public function set($key, $value, $ttl = null): bool + public function set(string $key, mixed $value, null|int|\DateInterval $ttl = null): bool { - if (!\is_string($key)) { - throw new InvalidArgumentException('$key is not a string:' . \print_r($key, true)); - } - return $this->setItem($key, $value, $ttl); } @@ -169,16 +141,8 @@ public function set($key, $value, $ttl = null): bool * * @return bool true on success and false on failure */ - public function setMultiple($values, $ttl = null): bool + public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null): bool { - if ( - !\is_array($values) - && - !($values instanceof \Traversable) - ) { - throw new InvalidArgumentException('$values is not iterable:' . \print_r($values, true)); - } - $results = []; foreach ((array) $values as $key => $value) { $results[] = $this->set($key, $value, $ttl); From dda492fffe33771723df852dec779b135d3ea389 Mon Sep 17 00:00:00 2001 From: Joshua Behrens Date: Sat, 20 May 2023 17:30:51 +0200 Subject: [PATCH 2/2] Update composer requirements to new type hint mixed --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index afd1351..caba968 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,8 @@ "psr/simple-cache-implementation": "1.0" }, "require": { - "php": ">=7.0.0", - "psr/simple-cache": "~1.0 || ~2.0" + "php": ">=8.0.0", + "psr/simple-cache": "~1.0 || ~2.0 || ~3.0" }, "require-dev": { "phpunit/phpunit": "~6.0 || ~7.0 || ~9.0"