diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..3a9251f
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,3 @@
+# These are supported funding model platforms
+
+github: byjg
diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index 9908d55..6dda630 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -36,6 +36,7 @@ jobs:
- uses: actions/checkout@v4
- run: composer install
- run: ./vendor/bin/phpunit --stderr
+ - run: ./vendor/bin/psalm
Documentation:
if: github.ref == 'refs/heads/master'
diff --git a/.run/PHPUnit.run.xml b/.run/PHPUnit.run.xml
new file mode 100644
index 0000000..7034700
--- /dev/null
+++ b/.run/PHPUnit.run.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.run/PSalm.run.xml b/.run/PSalm.run.xml
new file mode 100644
index 0000000..bd119ce
--- /dev/null
+++ b/.run/PSalm.run.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index f7ac5f3..0f6630b 100644
--- a/composer.json
+++ b/composer.json
@@ -6,6 +6,11 @@
"ByJG\\Cache\\": "src/"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "Tests\\": "tests/"
+ }
+ },
"require": {
"php": ">=8.1",
"psr/cache": "^1.0|^2.0|^3.0",
@@ -15,7 +20,7 @@
},
"require-dev": {
"phpunit/phpunit": "^9.6",
- "vimeo/psalm": "^6.0"
+ "vimeo/psalm": "^5.9"
},
"suggest": {
"ext-memcached": "*",
diff --git a/psalm.xml b/psalm.xml
new file mode 100644
index 0000000..ebabb1a
--- /dev/null
+++ b/psalm.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Psr16/ArrayCacheEngine.php b/src/Psr16/ArrayCacheEngine.php
index 865674d..67aa01f 100644
--- a/src/Psr16/ArrayCacheEngine.php
+++ b/src/Psr16/ArrayCacheEngine.php
@@ -6,16 +6,17 @@
use DateInterval;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
+use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
class ArrayCacheEngine extends BaseCacheEngine
{
- protected $cache = array();
+ protected array $cache = [];
- protected $logger = null;
+ protected LoggerInterface|null $logger = null;
- public function __construct($logger = null)
+ public function __construct(LoggerInterface|null $logger = null)
{
$this->logger = $logger;
if (is_null($logger)) {
diff --git a/src/Psr16/BaseCacheEngine.php b/src/Psr16/BaseCacheEngine.php
index bb59e7b..0c10629 100644
--- a/src/Psr16/BaseCacheEngine.php
+++ b/src/Psr16/BaseCacheEngine.php
@@ -17,8 +17,8 @@ abstract class BaseCacheEngine implements CacheInterface, CacheAvailabilityInter
/**
* @param string|iterable $keys
- * @param null $default
- * @return iterable
+ * @param mixed $default
+ * @return iterable
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function getMultiple(string|iterable $keys, mixed $default = null): iterable
@@ -36,11 +36,11 @@ public function getMultiple(string|iterable $keys, mixed $default = null): itera
/**
* @param iterable $values
- * @param null $ttl
+ * @param DateInterval|int|null $ttl
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
- public function setMultiple(iterable $values, $ttl = null): bool
+ public function setMultiple(iterable $values, DateInterval|int|null $ttl = null): bool
{
foreach ($values as $key => $value) {
$this->set($key, $value, $ttl);
@@ -87,11 +87,7 @@ protected function convertToSeconds(DateInterval|int|null $ttl): DateInterval|in
return $ttl;
}
- if ($ttl instanceof DateInterval) {
- return $ttl->days*86400 + $ttl->h*3600 + $ttl->i*60 + $ttl->s;
- }
-
- throw new InvalidArgumentException('Invalid TTL');
+ return $ttl->days*86400 + $ttl->h*3600 + $ttl->i*60 + $ttl->s;
}
diff --git a/src/Psr16/FileSystemCacheEngine.php b/src/Psr16/FileSystemCacheEngine.php
index 3dc8b05..b5b2d0f 100644
--- a/src/Psr16/FileSystemCacheEngine.php
+++ b/src/Psr16/FileSystemCacheEngine.php
@@ -5,17 +5,21 @@
use ByJG\Cache\CacheLockInterface;
use DateInterval;
use Exception;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
+use Psr\SimpleCache\InvalidArgumentException;
class FileSystemCacheEngine extends BaseCacheEngine implements CacheLockInterface
{
- protected $logger = null;
+ protected ?LoggerInterface $logger = null;
- protected $prefix = null;
- protected $path = null;
+ protected ?string $prefix = null;
+ protected ?string $path = null;
- public function __construct($prefix = 'cache', $path = null, $logger = null)
+ public function __construct(string $prefix = 'cache', ?string $path = null, ?LoggerInterface $logger = null)
{
$this->prefix = $prefix;
$this->path = $path ?? sys_get_temp_dir();
@@ -30,7 +34,9 @@ public function __construct($prefix = 'cache', $path = null, $logger = null)
* @param string $key The object KEY
* @param mixed $default IGNORED IN MEMCACHED.
* @return mixed Description
- * @throws \Psr\SimpleCache\InvalidArgumentException
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
*/
public function get(string $key, mixed $default = null): mixed
{
@@ -104,7 +110,7 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
$validUntil = $this->addToNow($ttl);
if (!empty($validUntil)) {
- file_put_contents($fileKey . ".ttl", $validUntil);
+ file_put_contents($fileKey . ".ttl", (string)$validUntil);
}
} catch (Exception $ex) {
$this->logger->warning("[Filesystem cache] I could not write to cache on file '" . basename($key) . "'. Switching to nocache=true mode.");
@@ -117,7 +123,6 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
/**
* @param string $key
* @return bool
- * @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function delete(string $key): bool
{
@@ -146,7 +151,7 @@ public function lock(string $key): void
* UnLock resource after set it.
* @param string $key
*/
- public function unlock($key): void
+ public function unlock(string $key): void
{
$this->logger->info("[Filesystem cache] Unlock '$key'");
@@ -158,12 +163,22 @@ public function unlock($key): void
}
}
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
+ */
public function isAvailable(): bool
{
return is_writable(dirname($this->fixKey('test')));
}
- protected function fixKey($key)
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
+ */
+ protected function fixKey(string $key): string
{
$key = $this->getKeyFromContainer($key);
@@ -177,6 +192,9 @@ protected function fixKey($key)
* Wipes clean the entire cache's keys.
*
* @return bool True on success and false on failure.
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
*/
public function clear(): bool
{
@@ -197,8 +215,9 @@ public function clear(): bool
*
* @param string $key The cache item key.
* @return bool
- * @throws \Psr\SimpleCache\InvalidArgumentException
- * MUST be thrown if the $key string is not a legal value.
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws \ByJG\Cache\Exception\InvalidArgumentException
*/
public function has(string $key): bool
{
diff --git a/src/Psr16/MemcachedEngine.php b/src/Psr16/MemcachedEngine.php
index e382b6b..299092a 100644
--- a/src/Psr16/MemcachedEngine.php
+++ b/src/Psr16/MemcachedEngine.php
@@ -2,9 +2,13 @@
namespace ByJG\Cache\Psr16;
+use ByJG\Cache\Exception\InvalidArgumentException;
use ByJG\Cache\Exception\StorageErrorException;
use DateInterval;
use Memcached;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
class MemcachedEngine extends BaseCacheEngine
@@ -12,15 +16,15 @@ class MemcachedEngine extends BaseCacheEngine
/**
*
- * @var Memcached
+ * @var Memcached|null
*/
- protected $memCached = null;
+ protected Memcached|null $memCached = null;
- protected $logger = null;
+ protected LoggerInterface|null $logger = null;
- protected $servers = null;
+ protected ?array $servers = null;
- public function __construct($servers = null, $logger = null)
+ public function __construct(?array $servers = null, $logger = null)
{
$this->servers = (array)$servers;
if (is_null($servers)) {
@@ -35,7 +39,13 @@ public function __construct($servers = null, $logger = null)
}
}
- protected function fixKey($key) {
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ */
+ protected function fixKey(string $key): string
+ {
$key = $this->getKeyFromContainer($key);
return "cache-" . $key;
}
@@ -43,13 +53,13 @@ protected function fixKey($key) {
/**
* @throws StorageErrorException
*/
- protected function lazyLoadMemCachedServers()
+ protected function lazyLoadMemCachedServers(): void
{
if (is_null($this->memCached)) {
$this->memCached = new Memcached();
foreach ($this->servers as $server) {
$data = explode(":", $server);
- $this->memCached->addServer($data[0], $data[1]);
+ $this->memCached->addServer($data[0], intval($data[1]));
$stats = $this->memCached->getStats();
if (!isset($stats[$server]) || $stats[$server]['pid'] === -1) {
@@ -60,9 +70,12 @@ protected function lazyLoadMemCachedServers()
}
/**
- * @param string $key The object KEY
- * @param int $default IGNORED IN MEMCACHED.
- * @return mixed Description
+ * @param string $key
+ * @param mixed|null $default
+ * @return mixed
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
* @throws StorageErrorException
*/
public function get(string $key, mixed $default = null): mixed
@@ -83,6 +96,9 @@ public function get(string $key, mixed $default = null): mixed
* @param mixed $value The object to be cached
* @param DateInterval|int|null $ttl The time to live in seconds of this objects
* @return bool If the object is successfully posted
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
* @throws StorageErrorException
*/
public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
@@ -103,6 +119,9 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
/**
* @param string $key
* @return bool
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
* @throws StorageErrorException
*/
public function delete(string $key): bool
@@ -141,6 +160,9 @@ public function clear(): bool
/**
* @param string $key
* @return bool
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
* @throws StorageErrorException
*/
public function has(string $key): bool
diff --git a/src/Psr16/NoCacheEngine.php b/src/Psr16/NoCacheEngine.php
index f453a62..c384277 100644
--- a/src/Psr16/NoCacheEngine.php
+++ b/src/Psr16/NoCacheEngine.php
@@ -3,14 +3,20 @@
namespace ByJG\Cache\Psr16;
use ByJG\Cache\CacheLockInterface;
+use ByJG\Cache\Exception\InvalidArgumentException;
use DateInterval;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
class NoCacheEngine extends BaseCacheEngine implements CacheLockInterface
{
/**
- * @param string $key The object KEY
- * @param int $default IGNORED IN MEMCACHED.
- * @return mixed Description
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
*/
public function get(string $key, mixed $default = null): mixed
{
@@ -19,10 +25,13 @@ public function get(string $key, mixed $default = null): mixed
}
/**
- * @param string $key The object Key
- * @param object $value The object to be cached
- * @param int $ttl The time to live in seconds of this objects
- * @return bool If the object is successfully posted
+ * @param string $key
+ * @param mixed $value
+ * @param DateInterval|int|null $ttl
+ * @return bool
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
*/
public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
{
@@ -33,6 +42,9 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
/**
* @param string $key
* @return bool
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
*/
public function delete(string $key): bool
{
@@ -82,9 +94,10 @@ public function clear(): bool
*
* @param string $key The cache item key.
* @return bool
- * @throws \Psr\SimpleCache\InvalidArgumentException
- * MUST be thrown if the $key string is not a legal value.
- */
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ */
public function has(string $key): bool
{
$key = $this->getKeyFromContainer($key);
diff --git a/src/Psr16/RedisCacheEngine.php b/src/Psr16/RedisCacheEngine.php
index 2b1089d..703b2b9 100644
--- a/src/Psr16/RedisCacheEngine.php
+++ b/src/Psr16/RedisCacheEngine.php
@@ -2,25 +2,31 @@
namespace ByJG\Cache\Psr16;
+use ByJG\Cache\Exception\InvalidArgumentException;
use DateInterval;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
+use Redis;
+use RedisException;
class RedisCacheEngine extends BaseCacheEngine
{
/**
*
- * @var \Redis
+ * @var Redis
*/
- protected $redis = null;
+ protected ?Redis $redis = null;
- protected $logger = null;
+ protected LoggerInterface|null $logger = null;
- protected $server = null;
+ protected ?string $server = null;
- protected $password = null;
+ protected ?string $password = null;
- public function __construct($server = null, $password = null, $logger = null)
+ public function __construct(?string $server = null, ?string $password = null, ?LoggerInterface $logger = null)
{
$this->server = $server;
if (is_null($server)) {
@@ -35,31 +41,44 @@ public function __construct($server = null, $password = null, $logger = null)
}
}
- protected function lazyLoadRedisServer()
+ /**
+ * @throws RedisException
+ */
+ protected function lazyLoadRedisServer(): void
{
if (is_null($this->redis)) {
- $this->redis = new \Redis();
+ $this->redis = new Redis();
$data = explode(":", $this->server);
- $this->redis->connect($data[0], isset($data[1]) ? $data[1] : 6379);
+ $this->redis->connect($data[0], intval($data[1] ?? 6379));
if (!empty($this->password)) {
$this->redis->auth($this->password);
}
- $this->redis->setOption(\Redis::OPT_SERIALIZER, \Redis::SERIALIZER_NONE);
+ $this->redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
$this->redis->info('redis_version');
}
}
- protected function fixKey($key) {
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws InvalidArgumentException
+ */
+ protected function fixKey(string $key): string
+ {
$key = $this->getKeyFromContainer($key);
return "cache:$key";
}
/**
- * @param string $key The object KEY
- * @param int $default IGNORED IN MEMCACHED.
- * @return mixed Description
+ * @param string $key
+ * @param mixed $default
+ * @return mixed
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ * @throws RedisException
*/
public function get(string $key, mixed $default = null): mixed
{
@@ -72,10 +91,14 @@ public function get(string $key, mixed $default = null): mixed
}
/**
- * @param string $key The object Key
- * @param object $value The object to be cached
- * @param int $ttl The time to live in seconds of this objects
- * @return bool If the object is successfully posted
+ * @param string $key
+ * @param mixed $value
+ * @param DateInterval|int|null $ttl
+ * @return bool
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ * @throws RedisException
*/
public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
{
@@ -89,6 +112,12 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
return true;
}
+ /**
+ * @throws NotFoundExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws RedisException
+ * @throws ContainerExceptionInterface
+ */
public function delete(string $key): bool
{
$this->lazyLoadRedisServer();
@@ -98,6 +127,12 @@ public function delete(string $key): bool
return true;
}
+ /**
+ * @throws NotFoundExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws RedisException
+ * @throws ContainerExceptionInterface
+ */
public function clear(): bool
{
$keys = $this->redis->keys('cache:*');
@@ -109,6 +144,12 @@ public function clear(): bool
return true;
}
+ /**
+ * @throws NotFoundExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws RedisException
+ * @throws ContainerExceptionInterface
+ */
public function has(string $key): bool
{
$result = $this->redis->exists($this->fixKey($key));
@@ -117,6 +158,10 @@ public function has(string $key): bool
return $result !== 0;
}
+ if ($result instanceof Redis) {
+ return true;
+ }
+
return $result;
}
diff --git a/src/Psr16/SessionCacheEngine.php b/src/Psr16/SessionCacheEngine.php
index cde9588..6b69cc1 100644
--- a/src/Psr16/SessionCacheEngine.php
+++ b/src/Psr16/SessionCacheEngine.php
@@ -2,37 +2,51 @@
namespace ByJG\Cache\Psr16;
+use ByJG\Cache\Exception\InvalidArgumentException;
use DateInterval;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
class SessionCacheEngine extends BaseCacheEngine
{
- protected $prefix = null;
+ protected string $prefix;
/**
* SessionCacheEngine constructor.
*
* @param string $prefix
*/
- public function __construct($prefix = 'cache')
+ public function __construct(string $prefix = 'cache')
{
$this->prefix = $prefix;
}
- protected function checkSession()
+ protected function checkSession(): void
{
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
}
- protected function keyName($key)
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws InvalidArgumentException
+ */
+ protected function keyName($key): string
{
$key = $this->getKeyFromContainer($key);
return $this->prefix . '-' . $key;
}
+ /**
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ * @throws ContainerExceptionInterface
+ * @throws \Psr\SimpleCache\InvalidArgumentException
+ */
public function get(string $key, mixed $default = null): mixed
{
$this->checkSession();
@@ -46,6 +60,11 @@ public function get(string $key, mixed $default = null): mixed
}
}
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ */
public function delete(string $key): bool
{
$this->checkSession();
diff --git a/src/Psr16/ShmopCacheEngine.php b/src/Psr16/ShmopCacheEngine.php
index 91f5844..d2ea023 100644
--- a/src/Psr16/ShmopCacheEngine.php
+++ b/src/Psr16/ShmopCacheEngine.php
@@ -5,6 +5,9 @@
use ByJG\Cache\Exception\InvalidArgumentException;
use ByJG\Cache\Exception\StorageErrorException;
use DateInterval;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\NotFoundExceptionInterface;
+use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
/**
@@ -24,11 +27,11 @@
*/
class ShmopCacheEngine extends BaseCacheEngine
{
- protected $logger = null;
+ protected LoggerInterface|null $logger = null;
- protected $config = [];
+ protected array $config = [];
- public function __construct($config = [], $logger = null)
+ public function __construct(array $config = [], ?LoggerInterface $logger = null)
{
$this->config = $config;
@@ -45,7 +48,12 @@ public function __construct($config = [], $logger = null)
}
}
- protected function getFilenameToken($key)
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ * @throws InvalidArgumentException
+ */
+ protected function getFilenameToken(string $key): string
{
$key = $this->getKeyFromContainer($key);
return sys_get_temp_dir() . '/shmop-' . sha1($key) . '.cache';
@@ -61,7 +69,7 @@ protected function getDefaultPermission()
return $this->config['default-permission'];
}
- protected function getFTok($file)
+ protected function getFTok(string $file): int
{
if (!file_exists($file)) {
touch($file);
@@ -73,6 +81,9 @@ protected function getFTok($file)
* @param string $key The object KEY
* @param mixed $default The time to live in seconds of the object. Depends on implementation.
* @return mixed The Object
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
*/
public function get(string $key, mixed $default = null): mixed
{
@@ -103,7 +114,7 @@ public function get(string $key, mixed $default = null): mixed
return unserialize($serialized);
}
- protected function isValidAge($file)
+ protected function isValidAge(string $file): bool
{
if (file_exists("$file.ttl")) {
$fileTtl = intval(file_get_contents("$file.ttl"));
@@ -127,7 +138,9 @@ protected function isValidAge($file)
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
* @return bool True on success and false on failure.
+ * @throws ContainerExceptionInterface
* @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
* @throws StorageErrorException
*/
public function set(string $key, mixed $value, DateInterval|int|null $ttl = null): bool
@@ -164,7 +177,7 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
$validUntil = $this->addToNow($ttl);
if (!empty($validUntil)) {
- file_put_contents("$file.ttl", $validUntil);
+ file_put_contents("$file.ttl", (string)$validUntil);
}
return true;
@@ -173,6 +186,9 @@ public function set(string $key, mixed $value, DateInterval|int|null $ttl = null
/**
* @param string $key
* @return bool
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
*/
public function delete(string $key): bool
{
@@ -188,7 +204,7 @@ public function delete(string $key): bool
return true;
}
- private function deleteFromFilenameToken($file)
+ private function deleteFromFilenameToken(string $file): void
{
$filekey = $this->getFTok($file);
$shm_id = @shmop_open($filekey, "w", 0, 0);
@@ -219,6 +235,11 @@ public function clear(): bool
return true;
}
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws InvalidArgumentException
+ * @throws NotFoundExceptionInterface
+ */
public function has(string $key): bool
{
$file = $this->getFilenameToken($key);
@@ -234,7 +255,7 @@ public function has(string $key): bool
return $this->isValidAge($file);
}
- return $exists;
+ return false;
}
diff --git a/src/Psr6/CachePool.php b/src/Psr6/CachePool.php
index bf37e35..e3141ce 100644
--- a/src/Psr6/CachePool.php
+++ b/src/Psr6/CachePool.php
@@ -11,9 +11,9 @@
class CachePool implements CacheItemPoolInterface
{
/**
- * @var CacheInterface
+ * @var BaseCacheEngine
*/
- protected CacheInterface $_cacheEngine;
+ protected BaseCacheEngine $_cacheEngine;
/**
* @var CacheItem
diff --git a/tests/BaseCacheTest.php b/tests/BaseCacheTest.php
index a0099be..ac24d6e 100644
--- a/tests/BaseCacheTest.php
+++ b/tests/BaseCacheTest.php
@@ -1,11 +1,9 @@
isAvailable()) {
// First time
- $items = $cacheEngine->getMultiple(['chave1', 'chave2']);
+ $items = [...$cacheEngine->getMultiple(['chave1', 'chave2'])];
$this->assertNull($items['chave1']);
$this->assertNull($items['chave2']);
- $items = $cacheEngine->getMultiple(['chave1', 'chave2'], 'default');
+ $items = [...$cacheEngine->getMultiple(['chave1', 'chave2'], 'default')];
$this->assertEquals('default', $items['chave1']);
$this->assertEquals('default', $items['chave2']);
@@ -73,7 +68,7 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)
// Get Object
if (!($cacheEngine instanceof NoCacheEngine)) {
- $item2 = $cacheEngine->getMultiple(['chave1', 'chave2']);
+ $item2 = [...$cacheEngine->getMultiple(['chave1', 'chave2'])];
$this->assertEquals('valor1', $item2['chave1']);
$this->assertEquals('valor2', $item2['chave2']);
}
@@ -82,7 +77,7 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)
$cacheEngine->deleteMultiple(['chave1', 'chave2']);
// Check Removed
- $items = $cacheEngine->getMultiple(['chave1', 'chave2']);
+ $items = [...$cacheEngine->getMultiple(['chave1', 'chave2'])];
$this->assertNull($items['chave1']);
$this->assertNull($items['chave2']);
} else {
@@ -92,7 +87,7 @@ public function testGetMultipleItems(BaseCacheEngine $cacheEngine)
/**
* @dataProvider CachePoolProvider
- * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
+ * @param BaseCacheEngine $cacheEngine
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function testTtl(BaseCacheEngine $cacheEngine)
@@ -129,7 +124,7 @@ public function testTtl(BaseCacheEngine $cacheEngine)
/**
* @dataProvider CachePoolProvider
- * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
+ * @param BaseCacheEngine $cacheEngine
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function testCacheObject(BaseCacheEngine $cacheEngine)
@@ -162,8 +157,7 @@ public function testCacheObject(BaseCacheEngine $cacheEngine)
/**
* @dataProvider CachePoolProvider
- * @param \ByJG\Cache\Psr16\BaseCacheEngine $cacheEngine
- * @throws \ByJG\Cache\InvalidArgumentException
+ * @param BaseCacheEngine $cacheEngine
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function testClear(BaseCacheEngine $cacheEngine)
diff --git a/tests/CachePSR6Test.php b/tests/CachePSR6Test.php
index 36bb268..649be98 100644
--- a/tests/CachePSR6Test.php
+++ b/tests/CachePSR6Test.php
@@ -1,13 +1,11 @@