From 19c3f0da0b441d834d6d78868f0066c10bdc8a95 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Wed, 26 Nov 2025 17:49:00 +0000 Subject: [PATCH 1/4] feat(cache): add native return types to all CacheInterface methods + remove deprecated `false` type in `getMetaData()` method + remove unnecessary @inheritDoc annotation --- system/Cache/CacheInterface.php | 31 ++++------ system/Cache/Handlers/BaseHandler.php | 4 +- system/Cache/Handlers/DummyHandler.php | 55 ++++------------ system/Cache/Handlers/FileHandler.php | 62 +++++-------------- system/Cache/Handlers/MemcachedHandler.php | 52 ++++------------ system/Cache/Handlers/PredisHandler.php | 50 +++------------ system/Cache/Handlers/RedisHandler.php | 50 +++------------ system/Cache/Handlers/WincacheHandler.php | 60 +++++------------- system/Test/Mock/MockCache.php | 32 +++------- .../system/Cache/Handlers/FileHandlerTest.php | 2 +- .../Cache/Handlers/MemcachedHandlerTest.php | 2 +- .../Cache/Handlers/RedisHandlerTest.php | 1 - user_guide_src/source/changelogs/v4.7.0.rst | 10 +++ 13 files changed, 108 insertions(+), 303 deletions(-) diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index 0902dcf6f80d..3ce56e07b1cb 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -17,19 +17,15 @@ interface CacheInterface { /** * Takes care of any handler-specific setup that must be done. - * - * @return void */ - public function initialize(); + public function initialize(): void; /** * Attempts to fetch an item from the cache store. * * @param string $key Cache item name - * - * @return mixed */ - public function get(string $key); + public function get(string $key): mixed; /** * Saves an item to the cache store. @@ -40,7 +36,7 @@ public function get(string $key); * * @return bool Success or failure */ - public function save(string $key, $value, int $ttl = 60); + public function save(string $key, $value, int $ttl = 60): bool; /** * Deletes a specific item from the cache store. @@ -49,7 +45,7 @@ public function save(string $key, $value, int $ttl = 60); * * @return bool Success or failure */ - public function delete(string $key); + public function delete(string $key): bool; /** * Deletes items from the cache store matching a given pattern. @@ -65,27 +61,23 @@ public function deleteMatching(string $pattern): int; * * @param string $key Cache ID * @param int $offset Step/value to increase by - * - * @return bool|int */ - public function increment(string $key, int $offset = 1); + public function increment(string $key, int $offset = 1): bool|int; /** * Performs atomic decrementation of a raw stored value. * * @param string $key Cache ID * @param int $offset Step/value to increase by - * - * @return bool|int */ - public function decrement(string $key, int $offset = 1); + public function decrement(string $key, int $offset = 1): bool|int; /** * Will delete all items in the entire cache. * * @return bool Success or failure */ - public function clean(); + public function clean(): bool; /** * Returns information on the entire cache. @@ -95,18 +87,17 @@ public function clean(); * * @return array|false|object|null */ - public function getCacheInfo(); + public function getCacheInfo(): array|false|object|null; /** * Returns detailed information about the specific item in the cache. * * @param string $key Cache item name. * - * @return array|false|null Returns null if the item does not exist, otherwise array - * with at least the 'expire' key for absolute epoch expiry (or null). - * Some handlers may return false when an item does not exist, which is deprecated. + * @return array|null Returns null if the item does not exist, otherwise array + * with at least the 'expire' key for absolute epoch expiry (or null). */ - public function getMetaData(string $key); + public function getMetaData(string $key): ?array; /** * Determines if the driver is supported on this system. diff --git a/system/Cache/Handlers/BaseHandler.php b/system/Cache/Handlers/BaseHandler.php index fa93ffe378f0..2d9aeff489d1 100644 --- a/system/Cache/Handlers/BaseHandler.php +++ b/system/Cache/Handlers/BaseHandler.php @@ -81,10 +81,8 @@ public static function validateKey($key, $prefix = ''): string * @param string $key Cache item name * @param int $ttl Time to live * @param Closure(): mixed $callback Callback return value - * - * @return mixed */ - public function remember(string $key, int $ttl, Closure $callback) + public function remember(string $key, int $ttl, Closure $callback): mixed { $value = $this->get($key); diff --git a/system/Cache/Handlers/DummyHandler.php b/system/Cache/Handlers/DummyHandler.php index 4328f62cfe05..9f526a30d33c 100644 --- a/system/Cache/Handlers/DummyHandler.php +++ b/system/Cache/Handlers/DummyHandler.php @@ -22,96 +22,63 @@ */ class DummyHandler extends BaseHandler { - /** - * {@inheritDoc} - */ - public function initialize() + public function initialize(): void { } - /** - * {@inheritDoc} - */ - public function get(string $key) + public function get(string $key): mixed { return null; } - /** - * {@inheritDoc} - */ - public function remember(string $key, int $ttl, Closure $callback) + public function remember(string $key, int $ttl, Closure $callback): mixed { return null; } /** - * {@inheritDoc} + * @param mixed $value */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { return true; } - /** - * {@inheritDoc} - */ - public function delete(string $key) + public function delete(string $key): bool { return true; } - /** - * {@inheritDoc} - */ public function deleteMatching(string $pattern): int { return 0; } - /** - * {@inheritDoc} - */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): bool { return true; } - /** - * {@inheritDoc} - */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): bool { return true; } - /** - * {@inheritDoc} - */ - public function clean() + public function clean(): bool { return true; } - /** - * {@inheritDoc} - */ - public function getCacheInfo() + public function getCacheInfo(): ?array { return null; } - /** - * {@inheritDoc} - */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { return null; } - /** - * {@inheritDoc} - */ public function isSupported(): bool { return true; diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index 5b3938e1db0b..ccb7d070200f 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -72,17 +72,11 @@ public function __construct(Cache $config) helper('filesystem'); } - /** - * {@inheritDoc} - */ - public function initialize() + public function initialize(): void { } - /** - * {@inheritDoc} - */ - public function get(string $key) + public function get(string $key): mixed { $key = static::validateKey($key, $this->prefix); $data = $this->getItem($key); @@ -91,9 +85,9 @@ public function get(string $key) } /** - * {@inheritDoc} + * @param mixed $value */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); @@ -119,19 +113,13 @@ public function save(string $key, $value, int $ttl = 60) return false; } - /** - * {@inheritDoc} - */ - public function delete(string $key) + public function delete(string $key): bool { $key = static::validateKey($key, $this->prefix); return is_file($this->path . $key) && unlink($this->path . $key); } - /** - * {@inheritDoc} - */ public function deleteMatching(string $pattern): int { $deleted = 0; @@ -145,10 +133,7 @@ public function deleteMatching(string $pattern): int return $deleted; } - /** - * {@inheritDoc} - */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): bool|int { $prefixedKey = static::validateKey($key, $this->prefix); $tmp = $this->getItem($prefixedKey); @@ -168,39 +153,27 @@ public function increment(string $key, int $offset = 1) return $this->save($key, $value, $ttl) ? $value : false; } - /** - * {@inheritDoc} - */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): bool|int { return $this->increment($key, -$offset); } - /** - * {@inheritDoc} - */ - public function clean() + public function clean(): bool { return delete_files($this->path, false, true); } - /** - * {@inheritDoc} - */ - public function getCacheInfo() + public function getCacheInfo(): array { return get_dir_file_info($this->path); } - /** - * {@inheritDoc} - */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { $key = static::validateKey($key, $this->prefix); if (false === $data = $this->getItem($key)) { - return false; // @TODO This will return null in a future release + return null; } return [ @@ -210,9 +183,6 @@ public function getMetaData(string $key) ]; } - /** - * {@inheritDoc} - */ public function isSupported(): bool { return is_writable($this->path); @@ -224,7 +194,7 @@ public function isSupported(): bool * * @return array{data: mixed, ttl: int, time: int}|false */ - protected function getItem(string $filename) + protected function getItem(string $filename): array|false { if (! is_file($this->path . $filename)) { return false; @@ -271,10 +241,8 @@ protected function getItem(string $filename) * @param string $path * @param string $data * @param string $mode - * - * @return bool */ - protected function writeFile($path, $data, $mode = 'wb') + protected function writeFile($path, $data, $mode = 'wb'): bool { if (($fp = @fopen($path, $mode)) === false) { return false; @@ -353,7 +321,7 @@ protected function deleteFiles(string $path, bool $delDir = false, bool $htdocs * relative_path: string, * }>|false */ - protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, bool $_recursion = false) + protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, bool $_recursion = false): array|false { static $filedata = []; @@ -412,7 +380,7 @@ protected function getDirFileInfo(string $sourceDir, bool $topLevelOnly = true, * fileperms?: int * }|false */ - protected function getFileInfo(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']) + protected function getFileInfo(string $file, $returnedValues = ['name', 'server_path', 'size', 'date']): array|false { if (! is_file($file)) { return false; diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index b19395dcb244..7e5e2afaea1b 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -69,10 +69,7 @@ public function __destruct() } } - /** - * {@inheritDoc} - */ - public function initialize() + public function initialize(): void { try { if (class_exists(Memcached::class)) { @@ -116,10 +113,7 @@ public function initialize() } } - /** - * {@inheritDoc} - */ - public function get(string $key) + public function get(string $key): mixed { $data = []; $key = static::validateKey($key, $this->prefix); @@ -145,9 +139,9 @@ public function get(string $key) } /** - * {@inheritDoc} + * @param mixed $value */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); @@ -170,28 +164,19 @@ public function save(string $key, $value, int $ttl = 60) return false; } - /** - * {@inheritDoc} - */ - public function delete(string $key) + public function delete(string $key): bool { $key = static::validateKey($key, $this->prefix); return $this->memcached->delete($key); } - /** - * {@inheritDoc} - */ public function deleteMatching(string $pattern): never { throw new BadMethodCallException('The deleteMatching method is not implemented for Memcached. You must select File, Redis or Predis handlers to use it.'); } - /** - * {@inheritDoc} - */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): false|int { if (! $this->config['raw']) { return false; @@ -202,10 +187,7 @@ public function increment(string $key, int $offset = 1) return $this->memcached->increment($key, $offset, $offset, 60); } - /** - * {@inheritDoc} - */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): false|int { if (! $this->config['raw']) { return false; @@ -218,33 +200,24 @@ public function decrement(string $key, int $offset = 1) return $this->memcached->decrement($key, $offset, $offset, 60); } - /** - * {@inheritDoc} - */ - public function clean() + public function clean(): bool { return $this->memcached->flush(); } - /** - * {@inheritDoc} - */ - public function getCacheInfo() + public function getCacheInfo(): array|false { return $this->memcached->getStats(); } - /** - * {@inheritDoc} - */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { $key = static::validateKey($key, $this->prefix); $stored = $this->memcached->get($key); // if not an array, don't try to count for PHP7.2 if (! is_array($stored) || count($stored) !== 3) { - return false; // @TODO This will return null in a future release + return null; } [$data, $time, $limit] = $stored; @@ -256,9 +229,6 @@ public function getMetaData(string $key) ]; } - /** - * {@inheritDoc} - */ public function isSupported(): bool { return extension_loaded('memcached') || extension_loaded('memcache'); diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index 46e697f50f0c..e4332785ceca 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -70,10 +70,7 @@ public function __construct(Cache $config) } } - /** - * {@inheritDoc} - */ - public function initialize() + public function initialize(): void { try { $this->redis = new Client($this->config, ['prefix' => $this->prefix]); @@ -83,10 +80,7 @@ public function initialize() } } - /** - * {@inheritDoc} - */ - public function get(string $key) + public function get(string $key): mixed { $key = static::validateKey($key); @@ -108,9 +102,9 @@ public function get(string $key) } /** - * {@inheritDoc} + * @param mixed $value */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { $key = static::validateKey($key); @@ -143,19 +137,13 @@ public function save(string $key, $value, int $ttl = 60) return true; } - /** - * {@inheritDoc} - */ - public function delete(string $key) + public function delete(string $key): bool { $key = static::validateKey($key); return $this->redis->del($key) === 1; } - /** - * {@inheritDoc} - */ public function deleteMatching(string $pattern): int { $matchedKeys = []; @@ -167,46 +155,31 @@ public function deleteMatching(string $pattern): int return $this->redis->del($matchedKeys); } - /** - * {@inheritDoc} - */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): int { $key = static::validateKey($key); return $this->redis->hincrby($key, 'data', $offset); } - /** - * {@inheritDoc} - */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): int { $key = static::validateKey($key); return $this->redis->hincrby($key, 'data', -$offset); } - /** - * {@inheritDoc} - */ - public function clean() + public function clean(): bool { return $this->redis->flushdb()->getPayload() === 'OK'; } - /** - * {@inheritDoc} - */ - public function getCacheInfo() + public function getCacheInfo(): array { return $this->redis->info(); } - /** - * {@inheritDoc} - */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { $key = static::validateKey($key); @@ -226,9 +199,6 @@ public function getMetaData(string $key) return null; } - /** - * {@inheritDoc} - */ public function isSupported(): bool { return class_exists(Client::class); diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index c3455693b8e2..8996cf64fc57 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -74,10 +74,7 @@ public function __destruct() } } - /** - * {@inheritDoc} - */ - public function initialize() + public function initialize(): void { $config = $this->config; @@ -111,10 +108,7 @@ public function initialize() } } - /** - * {@inheritDoc} - */ - public function get(string $key) + public function get(string $key): mixed { $key = static::validateKey($key, $this->prefix); $data = $this->redis->hMget($key, ['__ci_type', '__ci_value']); @@ -132,9 +126,9 @@ public function get(string $key) } /** - * {@inheritDoc} + * @param mixed $value */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); @@ -167,19 +161,13 @@ public function save(string $key, $value, int $ttl = 60) return true; } - /** - * {@inheritDoc} - */ - public function delete(string $key) + public function delete(string $key): bool { $key = static::validateKey($key, $this->prefix); return $this->redis->del($key) === 1; } - /** - * {@inheritDoc} - */ public function deleteMatching(string $pattern): int { /** @var list $matchedKeys */ @@ -199,44 +187,29 @@ public function deleteMatching(string $pattern): int return $this->redis->del($matchedKeys); } - /** - * {@inheritDoc} - */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): int { $key = static::validateKey($key, $this->prefix); return $this->redis->hIncrBy($key, '__ci_value', $offset); } - /** - * {@inheritDoc} - */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): int { return $this->increment($key, -$offset); } - /** - * {@inheritDoc} - */ - public function clean() + public function clean(): bool { return $this->redis->flushDB(); } - /** - * {@inheritDoc} - */ - public function getCacheInfo() + public function getCacheInfo(): array { return $this->redis->info(); } - /** - * {@inheritDoc} - */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { $value = $this->get($key); @@ -255,9 +228,6 @@ public function getMetaData(string $key) return null; } - /** - * {@inheritDoc} - */ public function isSupported(): bool { return extension_loaded('redis'); diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index 2207296457d7..a3fdd8a0d4fb 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -32,17 +32,11 @@ public function __construct(Cache $config) $this->prefix = $config->prefix; } - /** - * {@inheritDoc} - */ - public function initialize() + public function initialize(): void { } - /** - * {@inheritDoc} - */ - public function get(string $key) + public function get(string $key): mixed { $key = static::validateKey($key, $this->prefix); $success = false; @@ -54,73 +48,56 @@ public function get(string $key) } /** - * {@inheritDoc} + * @param mixed $value */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); return wincache_ucache_set($key, $value, $ttl); } - /** - * {@inheritDoc} - */ - public function delete(string $key) + public function delete(string $key): bool { $key = static::validateKey($key, $this->prefix); return wincache_ucache_delete($key); } - /** - * {@inheritDoc} - */ public function deleteMatching(string $pattern): never { throw new BadMethodCallException('The deleteMatching method is not implemented for Wincache. You must select File, Redis or Predis handlers to use it.'); } - /** - * {@inheritDoc} - */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): bool { $key = static::validateKey($key, $this->prefix); - return wincache_ucache_inc($key, $offset); + $result = wincache_ucache_inc($key, $offset); + + return $result !== false; } - /** - * {@inheritDoc} - */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): bool { $key = static::validateKey($key, $this->prefix); - return wincache_ucache_dec($key, $offset); + $result = wincache_ucache_dec($key, $offset); + + return $result !== false; } - /** - * {@inheritDoc} - */ - public function clean() + public function clean(): bool { return wincache_ucache_clear(); } - /** - * {@inheritDoc} - */ - public function getCacheInfo() + public function getCacheInfo(): array|false { return wincache_ucache_info(true); } - /** - * {@inheritDoc} - */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { $key = static::validateKey($key, $this->prefix); @@ -137,12 +114,9 @@ public function getMetaData(string $key) ]; } - return false; // @TODO This will return null in a future release + return null; } - /** - * {@inheritDoc} - */ public function isSupported(): bool { return extension_loaded('wincache') && ini_get('wincache.ucenabled'); diff --git a/system/Test/Mock/MockCache.php b/system/Test/Mock/MockCache.php index 07b44895cd09..27af8a1ad213 100644 --- a/system/Test/Mock/MockCache.php +++ b/system/Test/Mock/MockCache.php @@ -44,10 +44,8 @@ class MockCache extends BaseHandler implements CacheInterface /** * Takes care of any handler-specific setup that must be done. - * - * @return void */ - public function initialize() + public function initialize(): void { } @@ -58,7 +56,7 @@ public function initialize() * * @return bool|null */ - public function get(string $key) + public function get(string $key): mixed { $key = static::validateKey($key, $this->prefix); @@ -70,7 +68,7 @@ public function get(string $key) * * @return bool|null */ - public function remember(string $key, int $ttl, Closure $callback) + public function remember(string $key, int $ttl, Closure $callback): mixed { $value = $this->get($key); @@ -92,10 +90,8 @@ public function remember(string $key, int $ttl, Closure $callback) * @param string $key Cache item name * @param mixed $value the data to save * @param int $ttl Time To Live, in seconds (default 60) - * - * @return bool */ - public function save(string $key, $value, int $ttl = 60) + public function save(string $key, $value, int $ttl = 60): bool { if ($this->bypass) { return false; @@ -111,10 +107,8 @@ public function save(string $key, $value, int $ttl = 60) /** * Deletes a specific item from the cache store. - * - * @return bool */ - public function delete(string $key) + public function delete(string $key): bool { $key = static::validateKey($key, $this->prefix); @@ -146,10 +140,8 @@ public function deleteMatching(string $pattern): int /** * Performs atomic incrementation of a raw stored value. - * - * @return bool */ - public function increment(string $key, int $offset = 1) + public function increment(string $key, int $offset = 1): bool { $key = static::validateKey($key, $this->prefix); $data = $this->cache[$key] ?: null; @@ -165,10 +157,8 @@ public function increment(string $key, int $offset = 1) /** * Performs atomic decrementation of a raw stored value. - * - * @return bool */ - public function decrement(string $key, int $offset = 1) + public function decrement(string $key, int $offset = 1): bool { $key = static::validateKey($key, $this->prefix); @@ -185,10 +175,8 @@ public function decrement(string $key, int $offset = 1) /** * Will delete all items in the entire cache. - * - * @return bool */ - public function clean() + public function clean(): true { $this->cache = []; $this->expirations = []; @@ -204,7 +192,7 @@ public function clean() * * @return list Keys currently present in the store */ - public function getCacheInfo() + public function getCacheInfo(): array { return array_keys($this->cache); } @@ -216,7 +204,7 @@ public function getCacheInfo() * otherwise, array with the 'expire' key for * absolute epoch expiry (or null). */ - public function getMetaData(string $key) + public function getMetaData(string $key): ?array { // Misses return null if (! array_key_exists($key, $this->expirations)) { diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index 0819a5a9df06..6a709d60caf8 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -362,7 +362,7 @@ public function testFileHandler(): void public function testGetMetaDataMiss(): void { - $this->assertFalse($this->handler->getMetaData(self::$dummy)); + $this->assertNull($this->handler->getMetaData(self::$dummy)); } #[RequiresOperatingSystem('Linux|Darwin')] diff --git a/tests/system/Cache/Handlers/MemcachedHandlerTest.php b/tests/system/Cache/Handlers/MemcachedHandlerTest.php index f4114d4742e7..06ae6112a432 100644 --- a/tests/system/Cache/Handlers/MemcachedHandlerTest.php +++ b/tests/system/Cache/Handlers/MemcachedHandlerTest.php @@ -186,6 +186,6 @@ public function testIsSupported(): void public function testGetMetaDataMiss(): void { - $this->assertFalse($this->handler->getMetaData(self::$dummy)); + $this->assertNull($this->handler->getMetaData(self::$dummy)); } } diff --git a/tests/system/Cache/Handlers/RedisHandlerTest.php b/tests/system/Cache/Handlers/RedisHandlerTest.php index 467abc675372..6abf9f2eb0fa 100644 --- a/tests/system/Cache/Handlers/RedisHandlerTest.php +++ b/tests/system/Cache/Handlers/RedisHandlerTest.php @@ -222,7 +222,6 @@ public function testGetMetadataNotNull(): void $metadata = $this->handler->getMetaData(self::$key1); $this->assertNotNull($metadata); - $this->assertIsArray($metadata); } public function testIsSupported(): void diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index f9dcb6c82d3f..71b37e0b3b66 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -59,6 +59,15 @@ Method Signature Changes - ``CodeIgniter\HTTP\CURLRequest::setAuth()`` - ``CodeIgniter\HTTP\URI::setUserInfo()`` - ``CodeIgniter\Security\Security::derandomize()`` +- Added native return types to ``CacheInterface`` methods that were missing them. The following methods were updated: + - ``initialize(): void`` + - ``save(): bool`` + - ``delete(): bool`` + - ``increment(): bool|int`` + - ``decrement(): bool|int`` + - ``clean(): bool`` + - ``getCacheInfo(): array|object|false|null`` + - ``getMetaData(): ?array`` Removed Deprecated Items ======================== @@ -66,6 +75,7 @@ Removed Deprecated Items - **Text Helper:** The deprecated types in ``random_string()`` function: ``basic``, ``md5``, and ``sha1`` has been removed. - **BaseModel:** The deprecated method ``transformDataRowToArray()`` has been removed. - **CodeIgniter:** The deprecated ``CodeIgniter\CodeIgniter::resolvePlatformExtensions()`` has been removed. +- **Cache:** The deprecated return type ``false`` for ``CodeIgniter\Cache\CacheInterface::getMetaData()`` has been removed. ************ Enhancements From ff352672368c39933d4c7fb90e66a8acaa5cc609 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Wed, 26 Nov 2025 22:08:13 +0000 Subject: [PATCH 2/4] docs(changelogs): add note for WincacheHandler bug fix + clarify deprecation removal of `false` type for `CacheInterface::getMetaData()` --- user_guide_src/source/changelogs/v4.7.0.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 71b37e0b3b66..215fa842e6da 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -75,7 +75,7 @@ Removed Deprecated Items - **Text Helper:** The deprecated types in ``random_string()`` function: ``basic``, ``md5``, and ``sha1`` has been removed. - **BaseModel:** The deprecated method ``transformDataRowToArray()`` has been removed. - **CodeIgniter:** The deprecated ``CodeIgniter\CodeIgniter::resolvePlatformExtensions()`` has been removed. -- **Cache:** The deprecated return type ``false`` for ``CodeIgniter\Cache\CacheInterface::getMetaData()`` has been removed. +- **Cache:** The deprecated return type ``false`` for ``CodeIgniter\Cache\CacheInterface::getMetaData()`` has been replaced with ``null`` type. ************ Enhancements @@ -164,6 +164,7 @@ Bugs Fixed ********** - **Cookie:** The ``CookieInterface::SAMESITE_STRICT``, ``CookieInterface::SAMESITE_LAX``, and ``CookieInterface::SAMESITE_NONE`` constants are now written in ucfirst style to be consistent with usage in the rest of the framework. +- **Cache:** Changed ``WincacheHandler::increment()`` and ``WincacheHandler::decrement()`` to return ``bool`` instead of ``mixed``. See the repo's `CHANGELOG.md `_ From cdc619e6e9c671ca7d069e8170a1f3ab10c4e699 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Thu, 27 Nov 2025 15:01:10 +0000 Subject: [PATCH 3/4] feat(cache): set native type for $value param in CacheInterface::save() method --- system/Cache/CacheInterface.php | 2 +- system/Cache/Handlers/DummyHandler.php | 5 +---- system/Cache/Handlers/FileHandler.php | 5 +---- system/Cache/Handlers/MemcachedHandler.php | 5 +---- system/Cache/Handlers/PredisHandler.php | 5 +---- system/Cache/Handlers/RedisHandler.php | 5 +---- system/Cache/Handlers/WincacheHandler.php | 5 +---- 7 files changed, 7 insertions(+), 25 deletions(-) diff --git a/system/Cache/CacheInterface.php b/system/Cache/CacheInterface.php index 3ce56e07b1cb..9ae83f29283d 100644 --- a/system/Cache/CacheInterface.php +++ b/system/Cache/CacheInterface.php @@ -36,7 +36,7 @@ public function get(string $key): mixed; * * @return bool Success or failure */ - public function save(string $key, $value, int $ttl = 60): bool; + public function save(string $key, mixed $value, int $ttl = 60): bool; /** * Deletes a specific item from the cache store. diff --git a/system/Cache/Handlers/DummyHandler.php b/system/Cache/Handlers/DummyHandler.php index 9f526a30d33c..a30475965d6f 100644 --- a/system/Cache/Handlers/DummyHandler.php +++ b/system/Cache/Handlers/DummyHandler.php @@ -36,10 +36,7 @@ public function remember(string $key, int $ttl, Closure $callback): mixed return null; } - /** - * @param mixed $value - */ - public function save(string $key, $value, int $ttl = 60): bool + public function save(string $key, mixed $value, int $ttl = 60): bool { return true; } diff --git a/system/Cache/Handlers/FileHandler.php b/system/Cache/Handlers/FileHandler.php index ccb7d070200f..adc31c8f447c 100644 --- a/system/Cache/Handlers/FileHandler.php +++ b/system/Cache/Handlers/FileHandler.php @@ -84,10 +84,7 @@ public function get(string $key): mixed return is_array($data) ? $data['data'] : null; } - /** - * @param mixed $value - */ - public function save(string $key, $value, int $ttl = 60): bool + public function save(string $key, mixed $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); diff --git a/system/Cache/Handlers/MemcachedHandler.php b/system/Cache/Handlers/MemcachedHandler.php index 7e5e2afaea1b..14bc8e80a144 100644 --- a/system/Cache/Handlers/MemcachedHandler.php +++ b/system/Cache/Handlers/MemcachedHandler.php @@ -138,10 +138,7 @@ public function get(string $key): mixed return is_array($data) ? $data[0] : $data; } - /** - * @param mixed $value - */ - public function save(string $key, $value, int $ttl = 60): bool + public function save(string $key, mixed $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); diff --git a/system/Cache/Handlers/PredisHandler.php b/system/Cache/Handlers/PredisHandler.php index e4332785ceca..c7c7a6fdd760 100644 --- a/system/Cache/Handlers/PredisHandler.php +++ b/system/Cache/Handlers/PredisHandler.php @@ -101,10 +101,7 @@ public function get(string $key): mixed }; } - /** - * @param mixed $value - */ - public function save(string $key, $value, int $ttl = 60): bool + public function save(string $key, mixed $value, int $ttl = 60): bool { $key = static::validateKey($key); diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 8996cf64fc57..52b16b8e64ef 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -125,10 +125,7 @@ public function get(string $key): mixed }; } - /** - * @param mixed $value - */ - public function save(string $key, $value, int $ttl = 60): bool + public function save(string $key, mixed $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); diff --git a/system/Cache/Handlers/WincacheHandler.php b/system/Cache/Handlers/WincacheHandler.php index a3fdd8a0d4fb..5d520a05185e 100644 --- a/system/Cache/Handlers/WincacheHandler.php +++ b/system/Cache/Handlers/WincacheHandler.php @@ -47,10 +47,7 @@ public function get(string $key): mixed return $success ? $data : null; } - /** - * @param mixed $value - */ - public function save(string $key, $value, int $ttl = 60): bool + public function save(string $key, mixed $value, int $ttl = 60): bool { $key = static::validateKey($key, $this->prefix); From 2e2485911609fc27a6deab90dac4821f95354fd8 Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Fri, 28 Nov 2025 11:03:56 +0000 Subject: [PATCH 4/4] docs(changelogs): update method signature changes for CacheInterface --- user_guide_src/source/changelogs/v4.7.0.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 215fa842e6da..5a3d9a401b2c 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -59,15 +59,15 @@ Method Signature Changes - ``CodeIgniter\HTTP\CURLRequest::setAuth()`` - ``CodeIgniter\HTTP\URI::setUserInfo()`` - ``CodeIgniter\Security\Security::derandomize()`` -- Added native return types to ``CacheInterface`` methods that were missing them. The following methods were updated: - - ``initialize(): void`` - - ``save(): bool`` - - ``delete(): bool`` - - ``increment(): bool|int`` - - ``decrement(): bool|int`` - - ``clean(): bool`` - - ``getCacheInfo(): array|object|false|null`` - - ``getMetaData(): ?array`` +- Added native types to ``CacheInterface`` methods that were missing them. The following methods were updated: + - ``initialize()`` + - ``save()`` + - ``delete()`` + - ``increment()`` + - ``decrement()`` + - ``clean()`` + - ``getCacheInfo()`` + - ``getMetaData()`` Removed Deprecated Items ========================