From d60d227f127ec8c110aaa11ab72f0291e776eed1 Mon Sep 17 00:00:00 2001 From: Valentine Boineau Date: Mon, 7 Jun 2021 16:13:49 +0200 Subject: [PATCH] [Cache]Add Union Type --- .../Cache/Adapter/AdapterInterface.php | 2 +- .../Component/Cache/Adapter/ApcuAdapter.php | 2 +- .../Component/Cache/Adapter/ArrayAdapter.php | 6 +++--- .../Component/Cache/Adapter/ChainAdapter.php | 6 +++--- .../Cache/Adapter/CouchbaseBucketAdapter.php | 9 +++------ .../Component/Cache/Adapter/DoctrineAdapter.php | 2 +- .../Cache/Adapter/MemcachedAdapter.php | 4 ++-- .../Component/Cache/Adapter/NullAdapter.php | 8 ++++---- .../Component/Cache/Adapter/PdoAdapter.php | 4 ++-- .../Component/Cache/Adapter/PhpArrayAdapter.php | 6 +++--- .../Component/Cache/Adapter/PhpFilesAdapter.php | 6 +++--- .../Component/Cache/Adapter/ProxyAdapter.php | 8 ++++---- .../Component/Cache/Adapter/Psr16Adapter.php | 5 ++--- .../Component/Cache/Adapter/RedisAdapter.php | 9 +++++---- .../Cache/Adapter/RedisTagAwareAdapter.php | 4 ++-- .../Component/Cache/Adapter/TagAwareAdapter.php | 9 ++++----- .../Cache/Adapter/TraceableAdapter.php | 8 ++++---- src/Symfony/Component/Cache/CacheItem.php | 8 ++++---- .../Adapter/CouchbaseBucketAdapterTest.php | 2 +- .../Tests/Adapter/MemcachedAdapterTest.php | 2 +- .../Cache/Tests/Adapter/PdoPruneableTrait.php | 2 +- .../Cache/Tests/Adapter/ProxyAdapterTest.php | 2 +- .../Cache/Tests/Adapter/TagAwareAdapterTest.php | 2 +- .../Cache/Tests/Fixtures/ExternalAdapter.php | 2 +- .../Cache/Traits/AbstractAdapterTrait.php | 16 +++++++--------- .../Cache/Traits/FilesystemCommonTrait.php | 4 ++-- .../Component/Cache/Traits/FilesystemTrait.php | 2 +- .../Component/Cache/Traits/MemcachedTrait.php | 2 +- .../Cache/Traits/RedisClusterNodeProxy.php | 2 +- .../Component/Cache/Traits/RedisProxy.php | 8 ++++---- .../Component/Cache/Traits/RedisTrait.php | 17 ++++++++--------- 31 files changed, 81 insertions(+), 88 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/AdapterInterface.php b/src/Symfony/Component/Cache/Adapter/AdapterInterface.php index cbab77946fba7..e8a4504c8d1cc 100644 --- a/src/Symfony/Component/Cache/Adapter/AdapterInterface.php +++ b/src/Symfony/Component/Cache/Adapter/AdapterInterface.php @@ -29,7 +29,7 @@ interface AdapterInterface extends CacheItemPoolInterface * * @return CacheItem */ - public function getItem($key); + public function getItem(mixed $key); /** * {@inheritdoc} diff --git a/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php b/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php index 28ebce3e8fc48..6fd50280c97a5 100644 --- a/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ApcuAdapter.php @@ -77,7 +77,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { return apcu_exists($id); } diff --git a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php index f65fc0828266e..1db4b8e308e91 100644 --- a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php @@ -100,7 +100,7 @@ public function delete(string $key): bool * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) { if ($this->maxItems) { @@ -120,7 +120,7 @@ public function hasItem($key) /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { if (!$isHit = $this->hasItem($key)) { $value = null; @@ -151,7 +151,7 @@ public function getItems(array $keys = []) * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { \assert('' !== CacheItem::validateKey($key)); unset($this->values[$key], $this->expiries[$key]); diff --git a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php index 390d55e769317..d20c67b661adb 100644 --- a/src/Symfony/Component/Cache/Adapter/ChainAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ChainAdapter.php @@ -120,7 +120,7 @@ public function get(string $key, callable $callback, float $beta = null, array & /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { $syncItem = self::$syncItem; $misses = []; @@ -186,7 +186,7 @@ private function generateItems(iterable $items, int $adapterIndex) * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { foreach ($this->adapters as $adapter) { if ($adapter->hasItem($key)) { @@ -223,7 +223,7 @@ public function clear(string $prefix = '') * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { $deleted = true; $i = $this->adapterCount; diff --git a/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php b/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php index 36667f2a0dfb9..589f896f5ed31 100644 --- a/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php @@ -54,10 +54,7 @@ public function __construct(\CouchbaseBucket $bucket, string $namespace = '', in $this->marshaller = $marshaller ?? new DefaultMarshaller(); } - /** - * @param array|string $servers - */ - public static function createConnection($servers, array $options = []): \CouchbaseBucket + public static function createConnection(array | string $servers, array $options = []): \CouchbaseBucket { if (\is_string($servers)) { $servers = [$servers]; @@ -182,7 +179,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave($id): bool + protected function doHave(mixed $id): bool { return false !== $this->bucket->get($id); } @@ -190,7 +187,7 @@ protected function doHave($id): bool /** * {@inheritdoc} */ - protected function doClear($namespace): bool + protected function doClear(string $namespace): bool { if ('' === $namespace) { $this->bucket->manager()->flush(); diff --git a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php index dc70ea69738bf..1b4bd4f348d39 100644 --- a/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php @@ -65,7 +65,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { return $this->provider->contains($id); } diff --git a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php index 436880ff3785a..f131147c7fb67 100644 --- a/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php @@ -96,7 +96,7 @@ public static function isSupported() * * @throws \ErrorException When invalid options or servers are provided */ - public static function createConnection($servers, array $options = []) + public static function createConnection(array | string $servers, array $options = []) { if (\is_string($servers)) { $servers = [$servers]; @@ -285,7 +285,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode()); } diff --git a/src/Symfony/Component/Cache/Adapter/NullAdapter.php b/src/Symfony/Component/Cache/Adapter/NullAdapter.php index cbe77b241fb60..c463c483e6bb5 100644 --- a/src/Symfony/Component/Cache/Adapter/NullAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/NullAdapter.php @@ -50,7 +50,7 @@ public function get(string $key, callable $callback, float $beta = null, array & /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { return (self::$createCacheItem)($key); } @@ -68,7 +68,7 @@ public function getItems(array $keys = []) * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { return false; } @@ -88,7 +88,7 @@ public function clear(string $prefix = '') * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { return true; } @@ -136,7 +136,7 @@ public function commit() /** * {@inheritdoc} */ - public function delete(string $key): bool + public function delete(mixed $key): bool { return $this->deleteItem($key); } diff --git a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php index 1c36be8a08a62..3e45b8ae1ef11 100644 --- a/src/Symfony/Component/Cache/Adapter/PdoAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PdoAdapter.php @@ -66,7 +66,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface * @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION * @throws InvalidArgumentException When namespace contains invalid characters */ - public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null) + public function __construct(\PDO | Connection | string $connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null) { if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) { throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0])); @@ -259,7 +259,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { $sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)"; $stmt = $this->getConnection()->prepare($sql); diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php index 7e9b6b3f3ac64..561b3b7da8472 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php @@ -116,7 +116,7 @@ public function get(string $key, callable $callback, float $beta = null, array & /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { if (!\is_string($key)) { throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key))); @@ -167,7 +167,7 @@ public function getItems(array $keys = []) * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { if (!\is_string($key)) { throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key))); @@ -184,7 +184,7 @@ public function hasItem($key) * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { 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/Adapter/PhpFilesAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php index 212bde756e857..941f3ce5e5558 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php @@ -171,7 +171,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { if ($this->appendOnly && isset($this->values[$id])) { return true; @@ -292,7 +292,7 @@ protected function doDelete(array $ids) return $this->doCommonDelete($ids); } - protected function doUnlink($file) + protected function doUnlink(string $file) { unset(self::$valuesCache[$file]); @@ -323,7 +323,7 @@ class LazyValue { public $file; - public function __construct($file) + public function __construct(string $file) { $this->file = $file; } diff --git a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php index 8d9e6c63d788c..9e6d7e8766829 100644 --- a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php @@ -120,7 +120,7 @@ public function get(string $key, callable $callback, float $beta = null, array & /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { $item = $this->pool->getItem($this->getId($key)); @@ -146,7 +146,7 @@ public function getItems(array $keys = []) * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { return $this->pool->hasItem($this->getId($key)); } @@ -170,7 +170,7 @@ public function clear(string $prefix = '') * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { return $this->pool->deleteItem($this->getId($key)); } @@ -259,7 +259,7 @@ private function generateItems(iterable $items) } } - private function getId($key): string + private function getId(mixed $key): string { \assert('' !== CacheItem::validateKey($key)); diff --git a/src/Symfony/Component/Cache/Adapter/Psr16Adapter.php b/src/Symfony/Component/Cache/Adapter/Psr16Adapter.php index a13b20ebc21c6..51851bc91dc25 100644 --- a/src/Symfony/Component/Cache/Adapter/Psr16Adapter.php +++ b/src/Symfony/Component/Cache/Adapter/Psr16Adapter.php @@ -23,13 +23,12 @@ */ class Psr16Adapter extends AbstractAdapter implements PruneableInterface, ResettableInterface { + use ProxyTrait; /** * @internal */ protected const NS_SEPARATOR = '_'; - use ProxyTrait; - private $miss; public function __construct(CacheInterface $pool, string $namespace = '', int $defaultLifetime = 0) @@ -55,7 +54,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { return $this->pool->has($id); } diff --git a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php index 5c49f7afe1cb2..58aaf74fd1b7b 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisAdapter.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Cache\Adapter; use Symfony\Component\Cache\Marshaller\MarshallerInterface; +use Symfony\Component\Cache\Traits\RedisProxy; use Symfony\Component\Cache\Traits\RedisTrait; class RedisAdapter extends AbstractAdapter @@ -19,11 +20,11 @@ class RedisAdapter extends AbstractAdapter use RedisTrait; /** - * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient The redis client - * @param string $namespace The default namespace - * @param int $defaultLifetime The default lifetime + * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy $redisClient The redis client + * @param string $namespace The default namespace + * @param int $defaultLifetime The default lifetime */ - public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null) + public function __construct(mixed $redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null) { $this->init($redisClient, $namespace, $defaultLifetime, $marshaller); } diff --git a/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php index d245644e988c9..1d3c251693e4a 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php @@ -70,7 +70,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter * @param string $namespace The default namespace * @param int $defaultLifetime The default lifetime */ - public function __construct($redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null) + public function __construct(mixed $redisClient, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null) { if ($redisClient instanceof \Predis\ClientInterface && $redisClient->getConnection() instanceof ClusterInterface && !$redisClient->getConnection() instanceof PredisCluster) { throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redisClient->getConnection()))); @@ -256,7 +256,7 @@ protected function doInvalidate(array $tagIds): bool * * @return array Filtered list of the valid moved keys (only those that existed) */ - private function renameKeys($redis, array $ids): array + private function renameKeys(mixed $redis, array $ids): array { $newIds = []; $uniqueToken = bin2hex(random_bytes(10)); diff --git a/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php index 6f23a2a0355ca..0db9b4be324b5 100644 --- a/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php @@ -27,11 +27,10 @@ */ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterface, PruneableInterface, ResettableInterface, LoggerAwareInterface { - public const TAGS_PREFIX = "\0tags\0"; - use ContractsTrait; use LoggerAwareTrait; use ProxyTrait; + public const TAGS_PREFIX = "\0tags\0"; private $deferred = []; private $tags; @@ -155,7 +154,7 @@ public function invalidateTags(array $tags) * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { if ($this->deferred) { $this->commit(); @@ -186,7 +185,7 @@ public function hasItem($key) /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { foreach ($this->getItems([$key]) as $item) { return $item; @@ -252,7 +251,7 @@ public function clear(string $prefix = '') * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { return $this->deleteItems([$key]); } diff --git a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php index 99e74f2dc7978..4ff411e0aeee2 100644 --- a/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TraceableAdapter.php @@ -70,7 +70,7 @@ public function get(string $key, callable $callback, float $beta = null, array & /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { $event = $this->start(__FUNCTION__); try { @@ -92,7 +92,7 @@ public function getItem($key) * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { $event = $this->start(__FUNCTION__); try { @@ -107,7 +107,7 @@ public function hasItem($key) * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { $event = $this->start(__FUNCTION__); try { @@ -274,7 +274,7 @@ public function clearCalls() $this->calls = []; } - protected function start($name) + protected function start(string $name) { $this->calls[] = $event = new TraceableAdapterEvent(); $event->name = $name; diff --git a/src/Symfony/Component/Cache/CacheItem.php b/src/Symfony/Component/Cache/CacheItem.php index 38f1c8cd4d7ad..6d9997a834ebd 100644 --- a/src/Symfony/Component/Cache/CacheItem.php +++ b/src/Symfony/Component/Cache/CacheItem.php @@ -64,7 +64,7 @@ public function isHit(): bool * * @return $this */ - public function set($value): self + public function set(mixed $value): self { $this->value = $value; @@ -76,7 +76,7 @@ public function set($value): self * * @return $this */ - public function expiresAt($expiration): self + public function expiresAt(?\DateTimeInterface $expiration): self { if (null === $expiration) { $this->expiry = null; @@ -94,7 +94,7 @@ public function expiresAt($expiration): self * * @return $this */ - public function expiresAfter($time): self + public function expiresAfter(mixed $time): self { if (null === $time) { $this->expiry = null; @@ -155,7 +155,7 @@ public function getMetadata(): array * * @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/Tests/Adapter/CouchbaseBucketAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php index c72d6710f22e9..4bc50ee0e59a0 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/CouchbaseBucketAdapterTest.php @@ -45,7 +45,7 @@ public static function setupBeforeClass(): void /** * {@inheritdoc} */ - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $client = $defaultLifetime ? AbstractAdapter::createConnection('couchbase://' diff --git a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php index e3c7db7f07d04..01383f9cec01d 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php @@ -70,7 +70,7 @@ public function testOptions() /** * @dataProvider provideBadOptions */ - public function testBadOptions($name, $value) + public function testBadOptions(string $name, string $value) { $this->expectException(\Error::class); $this->expectExceptionMessage('Undefined constant Memcached::'); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PdoPruneableTrait.php b/src/Symfony/Component/Cache/Tests/Adapter/PdoPruneableTrait.php index 23f977fd6ee5b..d607d8d19384c 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PdoPruneableTrait.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PdoPruneableTrait.php @@ -13,7 +13,7 @@ trait PdoPruneableTrait { - protected function isPruned($cache, string $name): bool + protected function isPruned(object | null $cache, string $name): bool { $o = new \ReflectionObject($cache); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php index 378efa7b759f9..800188b116498 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php @@ -61,7 +61,7 @@ public function __construct(CacheItemInterface $item) $this->item = $item; } - public function getItem($key): CacheItem + public function getItem(mixed $key): CacheItem { return $this->item; } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php index 9a45adaa36e2b..e7a7b4be93c6a 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php @@ -29,7 +29,7 @@ class TagAwareAdapterTest extends AdapterTestCase { use TagAwareTestTrait; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new TagAwareAdapter(new FilesystemAdapter('', $defaultLifetime)); } diff --git a/src/Symfony/Component/Cache/Tests/Fixtures/ExternalAdapter.php b/src/Symfony/Component/Cache/Tests/Fixtures/ExternalAdapter.php index 2d2a4b1593a38..80a5e5d463fd3 100644 --- a/src/Symfony/Component/Cache/Tests/Fixtures/ExternalAdapter.php +++ b/src/Symfony/Component/Cache/Tests/Fixtures/ExternalAdapter.php @@ -29,7 +29,7 @@ public function __construct(int $defaultLifetime = 0) $this->cache = new ArrayAdapter($defaultLifetime); } - public function getItem($key): CacheItemInterface + public function getItem(mixed $key): CacheItemInterface { return $this->cache->getItem($key); } diff --git a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php index 30f76c089db17..b8b83f58c7ee1 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php @@ -63,7 +63,7 @@ abstract protected function doFetch(array $ids); * * @return bool True if item exists in the cache, false otherwise */ - abstract protected function doHave(string $id); + abstract protected function doHave(mixed $id); /** * Deletes all items in the pool. @@ -98,7 +98,7 @@ abstract protected function doSave(array $values, int $lifetime); * * @return bool */ - public function hasItem($key) + public function hasItem(mixed $key) { $id = $this->getId($key); @@ -158,7 +158,7 @@ public function clear(string $prefix = '') * * @return bool */ - public function deleteItem($key) + public function deleteItem(mixed $key) { return $this->deleteItems([$key]); } @@ -206,7 +206,7 @@ public function deleteItems(array $keys) /** * {@inheritdoc} */ - public function getItem($key) + public function getItem(mixed $key) { if ($this->deferred) { $this->commit(); @@ -291,11 +291,9 @@ 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; @@ -356,7 +354,7 @@ private function generateItems(iterable $items, array &$keys): iterable } } - private function getId($key) + private function getId(mixed $key) { if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { $this->ids = []; @@ -394,7 +392,7 @@ private function getId($key) /** * @internal */ - public static function handleUnserializeCallback($class) + public static function handleUnserializeCallback(string $class) { throw new \DomainException('Class not found: '.$class); } diff --git a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php index baf95d524a289..07433bd00bea1 100644 --- a/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php +++ b/src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php @@ -83,7 +83,7 @@ protected function doDelete(array $ids) return $ok; } - protected function doUnlink($file) + protected function doUnlink(string $file) { return @unlink($file); } @@ -166,7 +166,7 @@ private function scanHashDir(string $directory): \Generator /** * @internal */ - public static function throwError($type, $message, $file, $line) + public static function throwError(int $type, string $message, string $file, int $line) { throw new \ErrorException($message, 0, $type, $file, $line); } diff --git a/src/Symfony/Component/Cache/Traits/FilesystemTrait.php b/src/Symfony/Component/Cache/Traits/FilesystemTrait.php index 38b741f1cc9c3..3b4e9b0342809 100644 --- a/src/Symfony/Component/Cache/Traits/FilesystemTrait.php +++ b/src/Symfony/Component/Cache/Traits/FilesystemTrait.php @@ -81,7 +81,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { $file = $this->getFile($id); diff --git a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php index 7b61e73a44727..620e3d753e720 100644 --- a/src/Symfony/Component/Cache/Traits/MemcachedTrait.php +++ b/src/Symfony/Component/Cache/Traits/MemcachedTrait.php @@ -84,7 +84,7 @@ 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(array | string $servers, array $options = []) { if (\is_string($servers)) { $servers = [$servers]; diff --git a/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php b/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php index 7818f0b8df9c9..ec7078e371f02 100644 --- a/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php +++ b/src/Symfony/Component/Cache/Traits/RedisClusterNodeProxy.php @@ -30,7 +30,7 @@ class RedisClusterNodeProxy /** * @param \RedisCluster|RedisClusterProxy $redis */ - public function __construct(array $host, $redis) + public function __construct(array $host, \RedisCluster | RedisClusterProxy $redis) { $this->host = $host; $this->redis = $redis; diff --git a/src/Symfony/Component/Cache/Traits/RedisProxy.php b/src/Symfony/Component/Cache/Traits/RedisProxy.php index ec5cfabb3381c..4d1e490162bd4 100644 --- a/src/Symfony/Component/Cache/Traits/RedisProxy.php +++ b/src/Symfony/Component/Cache/Traits/RedisProxy.php @@ -35,28 +35,28 @@ public function __call(string $method, array $args) return $this->redis->{$method}(...$args); } - public function hscan($strKey, &$iIterator, $strPattern = null, $iCount = null) + public function hscan(string $strKey, int &$iIterator = null, string $strPattern = null, int $iCount = null) { $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis); return $this->redis->hscan($strKey, $iIterator, $strPattern, $iCount); } - public function scan(&$iIterator, $strPattern = null, $iCount = null) + public function scan(int &$iIterator = null, string $strPattern = null, int $iCount = null) { $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis); return $this->redis->scan($iIterator, $strPattern, $iCount); } - public function sscan($strKey, &$iIterator, $strPattern = null, $iCount = null) + public function sscan(string $strKey, int &$iIterator = null, string $strPattern = null, int $iCount = null) { $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis); return $this->redis->sscan($strKey, $iIterator, $strPattern, $iCount); } - public function zscan($strKey, &$iIterator, $strPattern = null, $iCount = null) + public function zscan(string $strKey, int &$iIterator = null, string $strPattern = null, int $iCount = null) { $this->ready ?: $this->ready = $this->initializer->__invoke($this->redis); diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 8f11e846126de..b20ab22b0052c 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -48,9 +48,9 @@ trait RedisTrait private $marshaller; /** - * @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface $redisClient + * @param \Predis\ClientInterface|\RedisCluster|\Redis|\RedisArray|RedisProxy $redisClient */ - private function init($redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller) + private function init(mixed $redisClient, string $namespace, int $defaultLifetime, ?MarshallerInterface $marshaller) { parent::__construct($namespace, $defaultLifetime); @@ -82,14 +82,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 - * - * @throws InvalidArgumentException when the DSN is invalid + * @param array $options See self::$defaultConnectionOptions * * @return \Redis|\RedisCluster|RedisClusterProxy|RedisProxy|\Predis\ClientInterface According to the "class" option + * + *@throws InvalidArgumentException when the DSN is invalid */ - public static function createConnection($dsn, array $options = []) + public static function createConnection(string $dsn, array $options = []) { if (0 === strpos($dsn, 'redis:')) { $scheme = 'redis'; @@ -364,7 +363,7 @@ protected function doFetch(array $ids) /** * {@inheritdoc} */ - protected function doHave(string $id) + protected function doHave(mixed $id) { return (bool) $this->redis->exists($id); } @@ -487,7 +486,7 @@ protected function doSave(array $values, int $lifetime) return $failed; } - private function pipeline(\Closure $generator, $redis = null): \Generator + private function pipeline(\Closure $generator, mixed $redis = null): \Generator { $ids = []; $redis = $redis ?? $this->redis;