From e35ef3f07f666ded9876c4c8fbab87454e14eed1 Mon Sep 17 00:00:00 2001 From: David Weichert Date: Tue, 12 Mar 2024 16:32:58 +0100 Subject: [PATCH] Changes for release compatible with psr/cache 3.0 - add type hints for arguments and return type hints - update dependencies - psr/cache ^3.0 - php (^8.0.0, same requirements as psr/cache ^3.0) --- composer.json | 3 +- src/CacheItemPoolAwareInterface.php | 3 -- src/CacheItemPoolAwareTrait.php | 7 ++--- src/NullCacheItem.php | 40 ++++++------------------- src/NullCacheItemPool.php | 46 +++++++---------------------- 5 files changed, 23 insertions(+), 76 deletions(-) diff --git a/composer.json b/composer.json index 7b2e5b2..7b811d4 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,8 @@ "license": "MIT", "minimum-stability": "stable", "require": { - "psr/cache": "^1.0" + "psr/cache": "^3.0", + "php": ">=8.0.0" }, "require-dev": { "phpunit/phpunit": "^11" diff --git a/src/CacheItemPoolAwareInterface.php b/src/CacheItemPoolAwareInterface.php index 2de80cd..2ad27f4 100644 --- a/src/CacheItemPoolAwareInterface.php +++ b/src/CacheItemPoolAwareInterface.php @@ -6,8 +6,5 @@ interface CacheItemPoolAwareInterface { - /** - * @param CacheItemPoolInterface $cacheItemPool - */ public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool); } diff --git a/src/CacheItemPoolAwareTrait.php b/src/CacheItemPoolAwareTrait.php index c1a219a..f9b64f7 100644 --- a/src/CacheItemPoolAwareTrait.php +++ b/src/CacheItemPoolAwareTrait.php @@ -6,12 +6,9 @@ trait CacheItemPoolAwareTrait { - /** - * @var CacheItemPoolInterface - */ - protected $cacheItemPool; + protected CacheItemPoolInterface $cacheItemPool; - public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool) + public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool): void { $this->cacheItemPool = $cacheItemPool; } diff --git a/src/NullCacheItem.php b/src/NullCacheItem.php index e5da8c1..80ccb01 100644 --- a/src/NullCacheItem.php +++ b/src/NullCacheItem.php @@ -2,67 +2,45 @@ namespace Metasyntactical\Psr\Cache; +use DateInterval; +use DateTimeInterface; use Psr\Cache\CacheItemInterface; final class NullCacheItem implements CacheItemInterface { - /** - * @var string - */ - private $key; + private string $key; - /** - * @param string $key - */ public function __construct($key) { $this->key = (string) $key; } - /** - * @inheritDoc - */ - public function getKey() + public function getKey(): string { return $this->key; } - /** - * @inheritDoc - */ - public function get() + public function get(): mixed { return null; } - /** - * @inheritDoc - */ - public function isHit() + public function isHit(): bool { return false; } - /** - * @inheritDoc - */ - public function set($value) + public function set(mixed $value): static { return $this; } - /** - * @inheritDoc - */ - public function expiresAt($expiration) + public function expiresAt(?DateTimeInterface $expiration): static { return $this; } - /** - * @inheritDoc - */ - public function expiresAfter($time) + public function expiresAfter(int|DateInterval|null $time): static { return $this; } diff --git a/src/NullCacheItemPool.php b/src/NullCacheItemPool.php index 18898ce..98d26ba 100644 --- a/src/NullCacheItemPool.php +++ b/src/NullCacheItemPool.php @@ -7,18 +7,13 @@ final class NullCacheItemPool implements CacheItemPoolInterface { - /** - * {@inheritdoc} - */ - public function getItem($key) + + public function getItem(string $key): CacheItemInterface { return new NullCacheItem($key); } - /** - * {@inheritdoc} - */ - public function getItems(array $keys = array()) + public function getItems(array $keys = []): iterable { return array_combine( $keys, @@ -31,58 +26,37 @@ function ($key) { ); } - /** - * {@inheritdoc} - */ - public function hasItem($key) + public function hasItem(string $key): bool { return false; } - /** - * {@inheritdoc} - */ - public function clear() + public function clear(): bool { return true; } - /** - * {@inheritdoc} - */ - public function deleteItem($key) + public function deleteItem(string $key): bool { return true; } - /** - * {@inheritdoc} - */ - public function deleteItems(array $keys) + public function deleteItems(array $keys): bool { return true; } - /** - * {@inheritdoc} - */ - public function save(CacheItemInterface $item) + public function save(CacheItemInterface $item): bool { return true; } - /** - * {@inheritdoc} - */ - public function saveDeferred(CacheItemInterface $item) + public function saveDeferred(CacheItemInterface $item): bool { return true; } - /** - * {@inheritdoc} - */ - public function commit() + public function commit(): bool { return true; }