Fix a bunch of phpstan issues
All checks were successful
Gitea - aviat/banker/pipeline/head This commit looks good
All checks were successful
Gitea - aviat/banker/pipeline/head This commit looks good
This commit is contained in:
parent
0f874ab0f9
commit
3362d66663
@ -17,6 +17,7 @@ namespace Aviat\Banker\Driver;
|
||||
|
||||
use Aviat\Banker\LoggerTrait;
|
||||
use Aviat\Banker\KeyValidateTrait;
|
||||
use DateInterval;
|
||||
use Psr\Log\LoggerAwareInterface;
|
||||
|
||||
/**
|
||||
@ -66,10 +67,10 @@ abstract class AbstractDriver implements DriverInterface, LoggerAwareInterface {
|
||||
* Set multiple cache values
|
||||
*
|
||||
* @param array $items
|
||||
* @param int|null $expires
|
||||
* @param DateInterval|int|null $expires
|
||||
* @return bool
|
||||
*/
|
||||
public function setMultiple(array $items, ?int $expires = NULL): bool
|
||||
public function setMultiple(array $items, DateInterval|int|null $expires = NULL): bool
|
||||
{
|
||||
$this->validateKeys($items, TRUE);
|
||||
|
||||
|
@ -98,18 +98,16 @@ class ApcuDriver extends AbstractDriver {
|
||||
* Set multiple cache values
|
||||
*
|
||||
* @param array $items
|
||||
* @param int|null $expires
|
||||
* @param DateInterval|int|null $expires
|
||||
* @return bool
|
||||
*/
|
||||
public function setMultiple(array $items, ?int $expires = NULL): bool
|
||||
public function setMultiple(array $items, DateInterval|int|null $expires = NULL): bool
|
||||
{
|
||||
$this->validateKeys($items, TRUE);
|
||||
|
||||
$ttl = $this->getTTLFromExpiration((int)$expires);
|
||||
|
||||
$errorKeys = ($expires === NULL)
|
||||
? apcu_store($items)
|
||||
: apcu_store($items, NULL, $ttl);
|
||||
: apcu_store($items, NULL, $this->getTTLFromExpiration($expires));
|
||||
|
||||
return empty($errorKeys);
|
||||
}
|
||||
@ -173,11 +171,16 @@ class ApcuDriver extends AbstractDriver {
|
||||
/**
|
||||
* Convert expiration date argument into TTL argument
|
||||
*
|
||||
* @param int|null $expires
|
||||
* @param DateInterval|int|null $expires
|
||||
* @return int
|
||||
*/
|
||||
protected function getTTLFromExpiration(?int $expires): int
|
||||
protected function getTTLFromExpiration(DateInterval|int|null $expires): int
|
||||
{
|
||||
if ($expires instanceof DateInterval)
|
||||
{
|
||||
return $expires->s;
|
||||
}
|
||||
|
||||
$ttl = (int)$expires - time();
|
||||
|
||||
return ($ttl < 0) ? 0 : $ttl;
|
||||
|
@ -130,6 +130,11 @@ class MemcachedDriver extends AbstractDriver {
|
||||
{
|
||||
$this->validateKey($key);
|
||||
|
||||
if ($expires instanceof DateInterval)
|
||||
{
|
||||
$expires = time() + $expires->s;
|
||||
}
|
||||
|
||||
return ($expires === NULL)
|
||||
? $this->conn->set($key, $value)
|
||||
: $this->conn->set($key, $value, $expires);
|
||||
@ -139,13 +144,18 @@ class MemcachedDriver extends AbstractDriver {
|
||||
* Set multiple cache values
|
||||
*
|
||||
* @param array $items
|
||||
* @param int|null $expires
|
||||
* @param DateInterval|int|null $expires
|
||||
* @return bool
|
||||
*/
|
||||
public function setMultiple(array $items, ?int $expires = NULL): bool
|
||||
public function setMultiple(array $items, DateInterval|int|null $expires = NULL): bool
|
||||
{
|
||||
$this->validateKeys($items, TRUE);
|
||||
|
||||
if ($expires instanceof DateInterval)
|
||||
{
|
||||
$expires = $expires->s;
|
||||
}
|
||||
|
||||
return ($expires === NULL)
|
||||
? $this->conn->setMulti($items)
|
||||
: $this->conn->setMulti($items, $expires);
|
||||
@ -174,6 +184,7 @@ class MemcachedDriver extends AbstractDriver {
|
||||
|
||||
$deleted = $this->conn->deleteMulti($keys);
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
if (is_array($deleted))
|
||||
{
|
||||
foreach ($deleted as $key => $status)
|
||||
|
@ -79,6 +79,11 @@ class RedisDriver extends AbstractDriver {
|
||||
public function get(string $key): mixed
|
||||
{
|
||||
$raw = $this->conn->get($key);
|
||||
if ($raw === NULL)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return unserialize($raw);
|
||||
}
|
||||
|
||||
@ -87,7 +92,7 @@ class RedisDriver extends AbstractDriver {
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param int|null $expires
|
||||
* @param DateInterval|int|null $expires
|
||||
* @return bool
|
||||
*/
|
||||
public function set(string $key, mixed $value, DateInterval|int|null $expires = NULL): bool
|
||||
|
@ -51,9 +51,9 @@ class ItemCollection extends ArrayIterator implements JsonSerializable {
|
||||
/**
|
||||
* Specify what data to serialize when using `json_encode`
|
||||
*
|
||||
* @return mixed - The full set of data to be serialized
|
||||
* @return array - The full set of data to be serialized
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
|
@ -213,10 +213,15 @@ final class Pool implements CacheItemPoolInterface, LoggerAwareInterface {
|
||||
* True if the item was successfully persisted. False if there was an error.
|
||||
*/
|
||||
public function save(CacheItemInterface $item): bool
|
||||
{
|
||||
if (method_exists($item, 'save'))
|
||||
{
|
||||
return $item->save();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a cache item to be persisted later.
|
||||
*
|
||||
|
@ -15,8 +15,7 @@
|
||||
*/
|
||||
namespace Aviat\Banker;
|
||||
|
||||
use Aviat\Banker\Driver\DriverInterface;
|
||||
use Aviat\Banker\Exception\InvalidArgumentException;
|
||||
use Aviat\Banker\Driver\AbstractDriver;
|
||||
|
||||
/**
|
||||
* Private trait for shared driver-related functionality
|
||||
@ -27,17 +26,17 @@ trait _Driver {
|
||||
/**
|
||||
* Driver class for handling the chosen caching backend
|
||||
*
|
||||
* @var DriverInterface
|
||||
* @var AbstractDriver
|
||||
*/
|
||||
private DriverInterface $driver;
|
||||
private AbstractDriver $driver;
|
||||
|
||||
/**
|
||||
* Instantiate the appropriate cache backend based on the config
|
||||
*
|
||||
* @param array $driverConfig
|
||||
* @return DriverInterface
|
||||
* @return AbstractDriver
|
||||
*/
|
||||
protected function loadDriver(array $driverConfig = []): DriverInterface
|
||||
protected function loadDriver(array $driverConfig = []): AbstractDriver
|
||||
{
|
||||
$driver = ucfirst(strtolower($driverConfig['driver'] ?? 'null'));
|
||||
$class = __NAMESPACE__ . "\\Driver\\${driver}Driver";
|
||||
|
Loading…
Reference in New Issue
Block a user