diff --git a/src/Symfony/Component/Cache/CacheItem.php b/src/Symfony/Component/Cache/CacheItem.php index 8145c49de257c..9623458293e95 100644 --- a/src/Symfony/Component/Cache/CacheItem.php +++ b/src/Symfony/Component/Cache/CacheItem.php @@ -151,11 +151,9 @@ public function getMetadata(): array /** * Validates a cache key according to PSR-6. * - * @param string $key The key to validate - * * @throws InvalidArgumentException When $key is not valid */ - public static function validateKey($key): string + public static function validateKey(mixed $key): string { if (!\is_string($key)) { throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key))); diff --git a/src/Symfony/Component/Cache/Messenger/EarlyExpirationMessage.php b/src/Symfony/Component/Cache/Messenger/EarlyExpirationMessage.php index e25c07e9a66be..94e3b97e88409 100644 --- a/src/Symfony/Component/Cache/Messenger/EarlyExpirationMessage.php +++ b/src/Symfony/Component/Cache/Messenger/EarlyExpirationMessage.php @@ -88,7 +88,7 @@ public function findCallback(ReverseContainer $reverseContainer): callable return $callback; } - private function __construct(CacheItem $item, string $pool, $callback) + private function __construct(CacheItem $item, string $pool, string|array $callback) { $this->item = $item; $this->pool = $pool; diff --git a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php index 30f76c089db17..d9374e8ee8ed3 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php @@ -291,14 +291,12 @@ public function saveDeferred(CacheItemInterface $item) * * Calling this method also clears the memoized namespace version and thus forces a resynchonization of it. * - * @param bool $enable - * * @return bool the previous state of versioning */ - public function enableVersioning($enable = true) + public function enableVersioning(bool $enable = true) { $wasEnabled = $this->versioningIsEnabled; - $this->versioningIsEnabled = (bool) $enable; + $this->versioningIsEnabled = $enable; $this->namespaceVersion = ''; $this->ids = []; @@ -356,7 +354,7 @@ private function generateItems(iterable $items, array &$keys): iterable } } - private function getId($key) + private function getId(string|int $key) { if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { $this->ids = []; diff --git a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php index 7b61e73a44727..ab6f8f41e7757 100644 --- a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php +++ b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php @@ -84,12 +84,10 @@ private function init(\Memcached $client, string $namespace, int $defaultLifetim * * @throws \ErrorException When invalid options or servers are provided */ - public static function createConnection($servers, array $options = []) + public static function createConnection(string|array $servers, array $options = []) { if (\is_string($servers)) { $servers = [$servers]; - } elseif (!\is_array($servers)) { - throw new InvalidArgumentException(sprintf('MemcachedAdapter::createClient() expects array or string as first argument, "%s" given.', \gettype($servers))); } if (!static::isSupported()) { throw new CacheException('Memcached >= 2.2.0 is required.'); @@ -273,7 +271,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave($id) + protected function doHave(string $id) { return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode()); } @@ -298,12 +296,12 @@ protected function doDelete(array $ids) /** * {@inheritdoc} */ - protected function doClear($namespace) + protected function doClear(string $namespace) { return '' === $namespace && $this->getClient()->flush(); } - private function checkResultCode($result) + private function checkResultCode(mixed $result) { $code = $this->client->getResultCode(); diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 618a2c3470007..8319d3ac4957c 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -47,10 +47,7 @@ trait RedisTrait private $redis; private $marshaller; - /** - * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient - */ - private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller) + private function init(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller) { parent::__construct($namespace, $defaultLifetime); @@ -58,10 +55,6 @@ private function init($redisClient, string $namespace, int $defaultLifetime, ?Ma throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0])); } - if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\ClientInterface && !$redisClient instanceof RedisProxy && !$redisClient instanceof RedisClusterProxy) { - throw new InvalidArgumentException(sprintf('"%s()" expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\ClientInterface, "%s" given.', __METHOD__, get_debug_type($redisClient))); - } - if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getOptions()->exceptions) { $options = clone $redisClient->getOptions(); \Closure::bind(function () { $this->options['exceptions'] = false; }, $options, $options)(); @@ -82,14 +75,13 @@ private function init($redisClient, string $namespace, int $defaultLifetime, ?Ma * - redis:///var/run/redis.sock * - redis://secret@/var/run/redis.sock/13 * - * @param string $dsn - * @param array $options See self::$defaultConnectionOptions + * @param array $options See self::$defaultConnectionOptions * * @throws InvalidArgumentException when the DSN is invalid * * @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option */ - public static function createConnection($dsn, array $options = []) + public static function createConnection(string $dsn, array $options = []) { if (0 === strpos($dsn, 'redis:')) { $scheme = 'redis'; @@ -498,7 +490,7 @@ protected function doSave(array $values, int $lifetime) return $failed; } - private function pipeline(\Closure $generator, $redis = null): \Generator + private function pipeline(\Closure $generator, object $redis = null): \Generator { $ids = []; $redis = $redis ?? $this->redis;