From 919afd211227ac61de44805fa3e396f97dfc4b2a Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 8 Sep 2019 22:49:38 +0200 Subject: [PATCH] [Cache] Add types to constructors and private/final/internal methods. --- .../Component/Cache/Adapter/ProxyAdapter.php | 2 +- src/Symfony/Component/Cache/CacheItem.php | 2 +- src/Symfony/Component/Cache/LockRegistry.php | 2 ++ .../Component/Cache/Simple/AbstractCache.php | 2 +- .../Component/Cache/Simple/ChainCache.php | 2 +- .../Component/Cache/Simple/PhpArrayCache.php | 2 +- .../Component/Cache/Simple/TraceableCache.php | 2 +- .../Adapter/AbstractRedisAdapterTest.php | 2 +- .../Cache/Tests/Adapter/ApcuAdapterTest.php | 2 +- .../Cache/Tests/Adapter/ArrayAdapterTest.php | 2 +- .../Cache/Tests/Adapter/ChainAdapterTest.php | 34 ++++--------------- .../Tests/Adapter/DoctrineAdapterTest.php | 2 +- .../Tests/Adapter/FilesystemAdapterTest.php | 6 ++-- .../Adapter/FilesystemTagAwareAdapterTest.php | 2 +- .../Tests/Adapter/MaxIdLengthAdapterTest.php | 2 +- .../Tests/Adapter/MemcachedAdapterTest.php | 12 +++---- .../Adapter/NamespacedProxyAdapterTest.php | 2 +- .../Cache/Tests/Adapter/PdoAdapterTest.php | 2 +- .../Tests/Adapter/PdoDbalAdapterTest.php | 2 +- .../Tests/Adapter/PhpArrayAdapterTest.php | 2 +- .../PhpArrayAdapterWithFallbackTest.php | 2 +- .../Tests/Adapter/PhpFilesAdapterTest.php | 2 +- .../Adapter/PredisTagAwareAdapterTest.php | 2 +- .../PredisTagAwareClusterAdapterTest.php | 2 +- .../PredisTagAwareRedisClusterAdapterTest.php | 2 +- .../Cache/Tests/Adapter/ProxyAdapterTest.php | 2 +- .../Cache/Tests/Adapter/Psr16AdapterTest.php | 2 +- .../Cache/Tests/Adapter/RedisAdapterTest.php | 14 ++++---- .../Tests/Adapter/RedisClusterAdapterTest.php | 6 ++-- .../Adapter/RedisTagAwareAdapterTest.php | 2 +- .../Adapter/RedisTagAwareArrayAdapterTest.php | 2 +- .../RedisTagAwareClusterAdapterTest.php | 2 +- .../Tests/Adapter/SimpleCacheAdapterTest.php | 2 +- .../Tests/Adapter/TagAwareAdapterTest.php | 28 ++++----------- ...TagAwareAndProxyAdapterIntegrationTest.php | 2 +- .../Tests/Adapter/TraceableAdapterTest.php | 2 +- .../Component/Cache/Tests/CacheItemTest.php | 2 +- .../Component/Cache/Tests/Psr16CacheTest.php | 4 +-- .../Tests/Simple/AbstractRedisCacheTest.php | 2 +- .../Cache/Tests/Simple/ApcuCacheTest.php | 2 +- .../Cache/Tests/Simple/ArrayCacheTest.php | 2 +- .../Cache/Tests/Simple/ChainCacheTest.php | 34 ++++--------------- .../Cache/Tests/Simple/DoctrineCacheTest.php | 2 +- .../Tests/Simple/FilesystemCacheTest.php | 4 +-- .../Cache/Tests/Simple/MemcachedCacheTest.php | 10 +++--- .../Simple/MemcachedCacheTextModeTest.php | 2 +- .../Cache/Tests/Simple/NullCacheTest.php | 2 +- .../Cache/Tests/Simple/PdoCacheTest.php | 2 +- .../Cache/Tests/Simple/PdoDbalCacheTest.php | 2 +- .../Simple/PhpArrayCacheWithFallbackTest.php | 2 +- .../Cache/Tests/Simple/PhpFilesCacheTest.php | 4 +-- .../Cache/Tests/Simple/Psr6CacheTest.php | 5 +-- .../Tests/Simple/Psr6CacheWithAdapterTest.php | 3 +- .../Simple/Psr6CacheWithoutAdapterTest.php | 3 +- .../Cache/Tests/Simple/RedisCacheTest.php | 8 ++--- .../Cache/Tests/Simple/TraceableCacheTest.php | 2 +- .../Cache/Tests/Traits/PdoPruneableTrait.php | 2 +- .../Cache/Tests/Traits/TagAwareTestTrait.php | 2 +- .../Cache/Traits/AbstractAdapterTrait.php | 2 +- .../Component/Cache/Traits/AbstractTrait.php | 2 +- .../Component/Cache/Traits/ArrayTrait.php | 2 +- .../Component/Cache/Traits/PhpFilesTrait.php | 2 +- .../Component/Cache/Traits/RedisTrait.php | 2 +- 63 files changed, 111 insertions(+), 160 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php index e1937fa71ae9f..157d65783bc6a 100644 --- a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php @@ -260,7 +260,7 @@ private function generateItems(iterable $items) } } - private function getId($key) + private function getId($key): string { CacheItem::validateKey($key); diff --git a/src/Symfony/Component/Cache/CacheItem.php b/src/Symfony/Component/Cache/CacheItem.php index fe7d717fca75b..c41c045925f99 100644 --- a/src/Symfony/Component/Cache/CacheItem.php +++ b/src/Symfony/Component/Cache/CacheItem.php @@ -185,7 +185,7 @@ public static function validateKey($key): string * * @internal */ - public static function log(LoggerInterface $logger = null, $message, $context = []) + public static function log(?LoggerInterface $logger, string $message, array $context = []) { if ($logger) { $logger->warning($message, $context); diff --git a/src/Symfony/Component/Cache/LockRegistry.php b/src/Symfony/Component/Cache/LockRegistry.php index 676fba5dca3f7..11d9f957562c5 100644 --- a/src/Symfony/Component/Cache/LockRegistry.php +++ b/src/Symfony/Component/Cache/LockRegistry.php @@ -131,6 +131,8 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s $logger && $logger->info('Item "{key}" not found while lock was released, now retrying', ['key' => $item->getKey()]); } } + + return null; } private static function open(int $key) diff --git a/src/Symfony/Component/Cache/Simple/AbstractCache.php b/src/Symfony/Component/Cache/Simple/AbstractCache.php index c01db702f7e44..b3477e94f36f0 100644 --- a/src/Symfony/Component/Cache/Simple/AbstractCache.php +++ b/src/Symfony/Component/Cache/Simple/AbstractCache.php @@ -177,7 +177,7 @@ private function normalizeTtl($ttl) throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given', \is_object($ttl) ? \get_class($ttl) : \gettype($ttl))); } - private function generateValues(iterable $values, array &$keys, $default) + private function generateValues(iterable $values, array &$keys, $default): iterable { try { foreach ($values as $id => $value) { diff --git a/src/Symfony/Component/Cache/Simple/ChainCache.php b/src/Symfony/Component/Cache/Simple/ChainCache.php index 683683dd87af1..57a169f63227d 100644 --- a/src/Symfony/Component/Cache/Simple/ChainCache.php +++ b/src/Symfony/Component/Cache/Simple/ChainCache.php @@ -92,7 +92,7 @@ public function getMultiple($keys, $default = null) return $this->generateItems($this->caches[0]->getMultiple($keys, $miss), 0, $miss, $default); } - private function generateItems(iterable $values, int $cacheIndex, $miss, $default) + private function generateItems(iterable $values, int $cacheIndex, $miss, $default): iterable { $missing = []; $nextCacheIndex = $cacheIndex + 1; diff --git a/src/Symfony/Component/Cache/Simple/PhpArrayCache.php b/src/Symfony/Component/Cache/Simple/PhpArrayCache.php index 15578c07b0b51..524df3c8a942b 100644 --- a/src/Symfony/Component/Cache/Simple/PhpArrayCache.php +++ b/src/Symfony/Component/Cache/Simple/PhpArrayCache.php @@ -229,7 +229,7 @@ public function setMultiple($values, $ttl = null) return $saved; } - private function generateItems(array $keys, $default) + private function generateItems(array $keys, $default): iterable { $fallbackKeys = []; diff --git a/src/Symfony/Component/Cache/Simple/TraceableCache.php b/src/Symfony/Component/Cache/Simple/TraceableCache.php index b1436d852b11d..eac77badd4425 100644 --- a/src/Symfony/Component/Cache/Simple/TraceableCache.php +++ b/src/Symfony/Component/Cache/Simple/TraceableCache.php @@ -236,7 +236,7 @@ public function getCalls() } } - private function start(string $name) + private function start(string $name): TraceableCacheEvent { $this->calls[] = $event = new TraceableCacheEvent(); $event->name = $name; diff --git a/src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php index 9b77e926d495a..6a686a9481f18 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php @@ -24,7 +24,7 @@ abstract class AbstractRedisAdapterTest extends AdapterTestCase protected static $redis; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new RedisAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php index a4673f12a21b2..10188607d1cb8 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php @@ -23,7 +23,7 @@ class ApcuAdapterTest extends AdapterTestCase 'testDefaultLifeTime' => 'Testing expiration slows down the test suite', ]; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN)) { $this->markTestSkipped('APCu extension is required.'); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php index 81f8e1470202b..ff37479cc17da 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php @@ -25,7 +25,7 @@ class ArrayAdapterTest extends AdapterTestCase 'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.', ]; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new ArrayAdapter($defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php index 02fe61480abe4..ffd598bc04b87 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Cache\Tests\Adapter; -use PHPUnit\Framework\MockObject\MockObject; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\ArrayAdapter; @@ -26,7 +25,7 @@ */ class ChainAdapterTest extends AdapterTestCase { - public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface { if ('testGetMetadata' === $testMethod) { return new ChainAdapter([new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime); @@ -70,14 +69,9 @@ public function testPrune() $this->assertFalse($cache->prune()); } - /** - * @return MockObject|PruneableCacheInterface - */ - private function getPruneableMock() + private function getPruneableMock(): AdapterInterface { - $pruneable = $this - ->getMockBuilder(PruneableCacheInterface::class) - ->getMock(); + $pruneable = $this->createMock([PruneableInterface::class, AdapterInterface::class]); $pruneable ->expects($this->atLeastOnce()) @@ -87,14 +81,9 @@ private function getPruneableMock() return $pruneable; } - /** - * @return MockObject|PruneableCacheInterface - */ - private function getFailingPruneableMock() + private function getFailingPruneableMock(): AdapterInterface { - $pruneable = $this - ->getMockBuilder(PruneableCacheInterface::class) - ->getMock(); + $pruneable = $this->createMock([PruneableInterface::class, AdapterInterface::class]); $pruneable ->expects($this->atLeastOnce()) @@ -104,17 +93,8 @@ private function getFailingPruneableMock() return $pruneable; } - /** - * @return MockObject|AdapterInterface - */ - private function getNonPruneableMock() + private function getNonPruneableMock(): AdapterInterface { - return $this - ->getMockBuilder(AdapterInterface::class) - ->getMock(); + return $this->createMock(AdapterInterface::class); } } - -interface PruneableCacheInterface extends PruneableInterface, AdapterInterface -{ -} diff --git a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php index dda3019c69ffc..310aa4387a490 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php @@ -27,7 +27,7 @@ class DoctrineAdapterTest extends AdapterTestCase 'testClearPrefix' => 'Doctrine cannot clear by prefix', ]; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new DoctrineAdapter(new ArrayCache($defaultLifetime), '', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/FilesystemAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/FilesystemAdapterTest.php index 5dbedcd444d8a..54264eeac5b42 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/FilesystemAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/FilesystemAdapterTest.php @@ -19,7 +19,7 @@ */ class FilesystemAdapterTest extends AdapterTestCase { - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new FilesystemAdapter('', $defaultLifetime); } @@ -29,7 +29,7 @@ public static function tearDownAfterClass(): void self::rmdir(sys_get_temp_dir().'/symfony-cache'); } - public static function rmdir($dir) + public static function rmdir(string $dir) { if (!file_exists($dir)) { return; @@ -51,7 +51,7 @@ public static function rmdir($dir) rmdir($dir); } - protected function isPruned(CacheItemPoolInterface $cache, $name) + protected function isPruned(CacheItemPoolInterface $cache, string $name): bool { $getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile'); $getFileMethod->setAccessible(true); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/FilesystemTagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/FilesystemTagAwareAdapterTest.php index 76c9a5817c4c6..a9f3407eae6da 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/FilesystemTagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/FilesystemTagAwareAdapterTest.php @@ -22,7 +22,7 @@ class FilesystemTagAwareAdapterTest extends FilesystemAdapterTest { use TagAwareTestTrait; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new FilesystemTagAwareAdapter('', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php index 724aa9451cbce..cc4d160aef4fc 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php @@ -80,7 +80,7 @@ abstract class MaxIdLengthAdapter extends AbstractAdapter { protected $maxIdLength = 50; - public function __construct($ns) + public function __construct(string $ns) { parent::__construct($ns); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php index 8238eaea056c8..9a60642e80249 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php @@ -39,7 +39,7 @@ public static function setUpBeforeClass(): void } } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client; @@ -73,7 +73,7 @@ public function testBadOptions($name, $value) MemcachedAdapter::createConnection([], [$name => $value]); } - public function provideBadOptions() + public function provideBadOptions(): array { return [ ['foo', 'bar'], @@ -109,7 +109,7 @@ public function testOptionSerializer() /** * @dataProvider provideServersSetting */ - public function testServersSetting($dsn, $host, $port) + public function testServersSetting(string $dsn, string $host, int $port) { $client1 = MemcachedAdapter::createConnection($dsn); $client2 = MemcachedAdapter::createConnection([$dsn]); @@ -125,7 +125,7 @@ public function testServersSetting($dsn, $host, $port) $this->assertSame([$expect], array_map($f, $client3->getServerList())); } - public function provideServersSetting() + public function provideServersSetting(): iterable { yield [ 'memcached://127.0.0.1/50', @@ -166,7 +166,7 @@ public function provideServersSetting() /** * @dataProvider provideDsnWithOptions */ - public function testDsnWithOptions($dsn, array $options, array $expectedOptions) + public function testDsnWithOptions(string $dsn, array $options, array $expectedOptions) { $client = MemcachedAdapter::createConnection($dsn, $options); @@ -175,7 +175,7 @@ public function testDsnWithOptions($dsn, array $options, array $expectedOptions) } } - public function provideDsnWithOptions() + public function provideDsnWithOptions(): iterable { if (!class_exists('\Memcached')) { self::markTestSkipped('Extension memcached required.'); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/NamespacedProxyAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/NamespacedProxyAdapterTest.php index 460ca0bc82162..a4edc7a608db5 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/NamespacedProxyAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/NamespacedProxyAdapterTest.php @@ -21,7 +21,7 @@ */ class NamespacedProxyAdapterTest extends ProxyAdapterTest { - public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface { if ('testGetMetadata' === $testMethod) { return new ProxyAdapter(new FilesystemAdapter(), 'foo', $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php index 4a09e851797c6..ec9e00d3c9e41 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php @@ -41,7 +41,7 @@ public static function tearDownAfterClass(): void @unlink(self::$dbFile); } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new PdoAdapter('sqlite:'.self::$dbFile, 'ns', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php index d4fa558411b32..6ad568d6cc5be 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php @@ -41,7 +41,7 @@ public static function tearDownAfterClass(): void @unlink(self::$dbFile); } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new PdoAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]), '', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php index ed5023b0786fc..4a5aa82d59f15 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php @@ -71,7 +71,7 @@ protected function tearDown(): void } } - public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface { if ('testGetMetadata' === $testMethod || 'testClearPrefix' === $testMethod) { return new PhpArrayAdapter(self::$file, new FilesystemAdapter()); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php index 32f52bae9bccc..694b63d89fa0f 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php @@ -43,7 +43,7 @@ protected function tearDown(): void } } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new PhpArrayAdapter(self::$file, new FilesystemAdapter('php-array-fallback', $defaultLifetime)); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterTest.php index 3e636174473d6..d204ef8d2993b 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterTest.php @@ -33,7 +33,7 @@ public static function tearDownAfterClass(): void FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache'); } - protected function isPruned(CacheItemPoolInterface $cache, $name) + protected function isPruned(CacheItemPoolInterface $cache, string $name): bool { $getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile'); $getFileMethod->setAccessible(true); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareAdapterTest.php index 390a73da5f78e..eedd3903a863c 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareAdapterTest.php @@ -25,7 +25,7 @@ protected function setUp(): void $this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite'; } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(\Predis\Client::class, self::$redis); $adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareClusterAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareClusterAdapterTest.php index 8339367593d06..77d51a9033932 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareClusterAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareClusterAdapterTest.php @@ -25,7 +25,7 @@ protected function setUp(): void $this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite'; } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(\Predis\Client::class, self::$redis); $adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareRedisClusterAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareRedisClusterAdapterTest.php index 813d52471587e..8357fffe39ea1 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareRedisClusterAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareRedisClusterAdapterTest.php @@ -25,7 +25,7 @@ protected function setUp(): void $this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite'; } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(\Predis\Client::class, self::$redis); $adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php index 6436428e7424a..0fbe94aac8440 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php @@ -29,7 +29,7 @@ class ProxyAdapterTest extends AdapterTestCase 'testPrune' => 'ProxyAdapter just proxies', ]; - public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface { if ('testGetMetadata' === $testMethod) { return new ProxyAdapter(new FilesystemAdapter(), '', $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/Psr16AdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/Psr16AdapterTest.php index 7d5f2423989b6..bdd5d04c564b6 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/Psr16AdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/Psr16AdapterTest.php @@ -27,7 +27,7 @@ class Psr16AdapterTest extends AdapterTestCase 'testClearPrefix' => 'SimpleCache cannot clear by prefix', ]; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new Psr16Adapter(new Psr16Cache(new FilesystemAdapter()), '', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php index 216d1373dbd0a..c78513724140b 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterTest.php @@ -24,7 +24,7 @@ public static function setUpBeforeClass(): void self::$redis = AbstractAdapter::createConnection('redis://'.getenv('REDIS_HOST'), ['lazy' => true]); } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $adapter = parent::createCachePool($defaultLifetime); $this->assertInstanceOf(RedisProxy::class, self::$redis); @@ -35,7 +35,7 @@ public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface /** * @dataProvider provideValidSchemes */ - public function testCreateConnection($dsnScheme) + public function testCreateConnection(string $dsnScheme) { $redis = RedisAdapter::createConnection($dsnScheme.':?host[h1]&host[h2]&host[/foo:]'); $this->assertInstanceOf(\RedisArray::class, $redis); @@ -65,14 +65,14 @@ public function testCreateConnection($dsnScheme) /** * @dataProvider provideFailedCreateConnection */ - public function testFailedCreateConnection($dsn) + public function testFailedCreateConnection(string $dsn) { $this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException'); $this->expectExceptionMessage('Redis connection failed'); RedisAdapter::createConnection($dsn); } - public function provideFailedCreateConnection() + public function provideFailedCreateConnection(): array { return [ ['redis://localhost:1234'], @@ -84,14 +84,14 @@ public function provideFailedCreateConnection() /** * @dataProvider provideInvalidCreateConnection */ - public function testInvalidCreateConnection($dsn) + public function testInvalidCreateConnection(string $dsn) { $this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException'); $this->expectExceptionMessage('Invalid Redis DSN'); RedisAdapter::createConnection($dsn); } - public function provideValidSchemes() + public function provideValidSchemes(): array { return [ ['redis'], @@ -99,7 +99,7 @@ public function provideValidSchemes() ]; } - public function provideInvalidCreateConnection() + public function provideInvalidCreateConnection(): array { return [ ['foo://localhost'], diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisClusterAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisClusterAdapterTest.php index 821259b78fdcf..d1dfe34fe8eae 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisClusterAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisClusterAdapterTest.php @@ -30,7 +30,7 @@ public static function setUpBeforeClass(): void self::$redis = AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['lazy' => true, 'redis_cluster' => true]); } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(RedisClusterProxy::class, self::$redis); $adapter = new RedisAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); @@ -41,14 +41,14 @@ public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface /** * @dataProvider provideFailedCreateConnection */ - public function testFailedCreateConnection($dsn) + public function testFailedCreateConnection(string $dsn) { $this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException'); $this->expectExceptionMessage('Redis connection failed'); RedisAdapter::createConnection($dsn); } - public function provideFailedCreateConnection() + public function provideFailedCreateConnection(): array { return [ ['redis://localhost:1234?redis_cluster=1'], diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareAdapterTest.php index b88af7b7335e9..5f8eef7c56ec0 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareAdapterTest.php @@ -26,7 +26,7 @@ protected function setUp(): void $this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite'; } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(RedisProxy::class, self::$redis); $adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareArrayAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareArrayAdapterTest.php index 5fcf781cd9f8c..8f9f87c8fe6ee 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareArrayAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareArrayAdapterTest.php @@ -25,7 +25,7 @@ protected function setUp(): void $this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite'; } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(\RedisArray::class, self::$redis); $adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareClusterAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareClusterAdapterTest.php index 3deb0c264a85f..d179abde1ebbb 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareClusterAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/RedisTagAwareClusterAdapterTest.php @@ -26,7 +26,7 @@ protected function setUp(): void $this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite'; } - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { $this->assertInstanceOf(RedisClusterProxy::class, self::$redis); $adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/SimpleCacheAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/SimpleCacheAdapterTest.php index 626ba4733141c..b4e185fcc9c24 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/SimpleCacheAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/SimpleCacheAdapterTest.php @@ -27,7 +27,7 @@ class SimpleCacheAdapterTest extends AdapterTestCase 'testClearPrefix' => 'SimpleCache cannot clear by prefix', ]; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new SimpleCacheAdapter(new FilesystemCache(), '', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php index 27731deb2bea8..a945267f4d6bc 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Cache\Adapter\AdapterInterface; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\TagAwareAdapter; +use Symfony\Component\Cache\PruneableInterface; use Symfony\Component\Cache\Tests\Traits\TagAwareTestTrait; /** @@ -66,14 +67,9 @@ public function testPrune() $this->assertFalse($cache->prune()); } - /** - * @return MockObject|PruneableCacheInterface - */ - private function getPruneableMock() + private function getPruneableMock(): AdapterInterface { - $pruneable = $this - ->getMockBuilder(PruneableCacheInterface::class) - ->getMock(); + $pruneable = $this->createMock([PruneableInterface::class, AdapterInterface::class]); $pruneable ->expects($this->atLeastOnce()) @@ -83,14 +79,9 @@ private function getPruneableMock() return $pruneable; } - /** - * @return MockObject|PruneableCacheInterface - */ - private function getFailingPruneableMock() + private function getFailingPruneableMock(): AdapterInterface { - $pruneable = $this - ->getMockBuilder(PruneableCacheInterface::class) - ->getMock(); + $pruneable = $this->createMock([PruneableInterface::class, AdapterInterface::class]); $pruneable ->expects($this->atLeastOnce()) @@ -100,13 +91,8 @@ private function getFailingPruneableMock() return $pruneable; } - /** - * @return MockObject|AdapterInterface - */ - private function getNonPruneableMock() + private function getNonPruneableMock(): AdapterInterface { - return $this - ->getMockBuilder(AdapterInterface::class) - ->getMock(); + return $this->createMock(AdapterInterface::class); } } diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php index b11c1f2870545..e53b40702860d 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php @@ -26,7 +26,7 @@ public function testIntegrationUsingProxiedAdapter(CacheItemPoolInterface $proxi $this->assertSame('bar', $cache->getItem('foo')->get()); } - public function dataProvider() + public function dataProvider(): array { return [ [new ArrayAdapter()], diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TraceableAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TraceableAdapterTest.php index 3d531f5caf162..3a573dc4314ed 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TraceableAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TraceableAdapterTest.php @@ -24,7 +24,7 @@ class TraceableAdapterTest extends AdapterTestCase 'testPrune' => 'TraceableAdapter just proxies', ]; - public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface + public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface { return new TraceableAdapter(new FilesystemAdapter('', $defaultLifetime)); } diff --git a/src/Symfony/Component/Cache/Tests/CacheItemTest.php b/src/Symfony/Component/Cache/Tests/CacheItemTest.php index b36b6343a8bab..3b756f571f69b 100644 --- a/src/Symfony/Component/Cache/Tests/CacheItemTest.php +++ b/src/Symfony/Component/Cache/Tests/CacheItemTest.php @@ -31,7 +31,7 @@ public function testInvalidKey($key) CacheItem::validateKey($key); } - public function provideInvalidKey() + public function provideInvalidKey(): array { return [ [''], diff --git a/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php b/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php index f3a027cbfbe88..094be128bbc93 100644 --- a/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php @@ -40,7 +40,7 @@ protected function setUp(): void } } - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new Psr16Cache(new FilesystemAdapter('', $defaultLifetime)); } @@ -146,7 +146,7 @@ public function testPrune() $cache->clear(); } - protected function isPruned($cache, $name) + protected function isPruned(CacheInterface $cache, string $name): bool { if (Psr16Cache::class !== \get_class($cache)) { $this->fail('Test classes for pruneable caches must implement `isPruned($cache, $name)` method.'); diff --git a/src/Symfony/Component/Cache/Tests/Simple/AbstractRedisCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/AbstractRedisCacheTest.php index b9bc266ab5389..4023c43105c14 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/AbstractRedisCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/AbstractRedisCacheTest.php @@ -27,7 +27,7 @@ abstract class AbstractRedisCacheTest extends CacheTestCase protected static $redis; - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new RedisCache(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/ApcuCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/ApcuCacheTest.php index 03e3f262a6de3..0f5c87e226db7 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/ApcuCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/ApcuCacheTest.php @@ -25,7 +25,7 @@ class ApcuCacheTest extends CacheTestCase 'testDefaultLifeTime' => 'Testing expiration slows down the test suite', ]; - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) || ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))) { $this->markTestSkipped('APCu extension is required.'); diff --git a/src/Symfony/Component/Cache/Tests/Simple/ArrayCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/ArrayCacheTest.php index 15fb83975dbc9..8d21f4f4914d4 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/ArrayCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/ArrayCacheTest.php @@ -20,7 +20,7 @@ */ class ArrayCacheTest extends CacheTestCase { - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new ArrayCache($defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/ChainCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/ChainCacheTest.php index 38b4bb8dd4713..9198c8f46a5df 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/ChainCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/ChainCacheTest.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Cache\Tests\Simple; -use PHPUnit\Framework\MockObject\MockObject; use Psr\SimpleCache\CacheInterface; use Symfony\Component\Cache\PruneableInterface; use Symfony\Component\Cache\Simple\ArrayCache; @@ -24,7 +23,7 @@ */ class ChainCacheTest extends CacheTestCase { - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new ChainCache([new ArrayCache($defaultLifetime), new FilesystemCache('', $defaultLifetime)], $defaultLifetime); } @@ -64,14 +63,9 @@ public function testPrune() $this->assertFalse($cache->prune()); } - /** - * @return MockObject|PruneableCacheInterface - */ - private function getPruneableMock() + private function getPruneableMock(): CacheInterface { - $pruneable = $this - ->getMockBuilder(PruneableCacheInterface::class) - ->getMock(); + $pruneable = $this->createMock([CacheInterface::class, PruneableInterface::class]); $pruneable ->expects($this->atLeastOnce()) @@ -81,14 +75,9 @@ private function getPruneableMock() return $pruneable; } - /** - * @return MockObject|PruneableCacheInterface - */ - private function getFailingPruneableMock() + private function getFailingPruneableMock(): CacheInterface { - $pruneable = $this - ->getMockBuilder(PruneableCacheInterface::class) - ->getMock(); + $pruneable = $this->createMock([CacheInterface::class, PruneableInterface::class]); $pruneable ->expects($this->atLeastOnce()) @@ -98,17 +87,8 @@ private function getFailingPruneableMock() return $pruneable; } - /** - * @return MockObject|CacheInterface - */ - private function getNonPruneableMock() + private function getNonPruneableMock(): CacheInterface { - return $this - ->getMockBuilder(CacheInterface::class) - ->getMock(); + return $this->createMock(CacheInterface::class); } } - -interface PruneableCacheInterface extends PruneableInterface, CacheInterface -{ -} diff --git a/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php index 150c1f6abb080..ad7a475d92fdf 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php @@ -26,7 +26,7 @@ class DoctrineCacheTest extends CacheTestCase 'testNotUnserializable' => 'ArrayCache does not use serialize/unserialize', ]; - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new DoctrineCache(new ArrayCache($defaultLifetime), '', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/FilesystemCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/FilesystemCacheTest.php index 31eacdbdb4e11..b4b7c8ae5b483 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/FilesystemCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/FilesystemCacheTest.php @@ -20,12 +20,12 @@ */ class FilesystemCacheTest extends CacheTestCase { - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new FilesystemCache('', $defaultLifetime); } - protected function isPruned(CacheInterface $cache, $name) + protected function isPruned(CacheInterface $cache, string $name): bool { $getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile'); $getFileMethod->setAccessible(true); diff --git a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php index c07f9f10ff087..75bf47246c933 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php @@ -42,7 +42,7 @@ public static function setUpBeforeClass(): void } } - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { $client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['binary_protocol' => false]) : self::$client; @@ -78,14 +78,14 @@ public function testOptions() /** * @dataProvider provideBadOptions */ - public function testBadOptions($name, $value) + public function testBadOptions(string $name, $value) { $this->expectException('ErrorException'); $this->expectExceptionMessage('constant(): Couldn\'t find constant Memcached::'); MemcachedCache::createConnection([], [$name => $value]); } - public function provideBadOptions() + public function provideBadOptions(): array { return [ ['foo', 'bar'], @@ -120,7 +120,7 @@ public function testOptionSerializer() /** * @dataProvider provideServersSetting */ - public function testServersSetting($dsn, $host, $port) + public function testServersSetting(string $dsn, string $host, int $port) { $client1 = MemcachedCache::createConnection($dsn); $client2 = MemcachedCache::createConnection([$dsn]); @@ -136,7 +136,7 @@ public function testServersSetting($dsn, $host, $port) $this->assertSame([$expect], array_map($f, $client3->getServerList())); } - public function provideServersSetting() + public function provideServersSetting(): iterable { yield [ 'memcached://127.0.0.1/50', diff --git a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTextModeTest.php b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTextModeTest.php index 1e749ba72e80e..57b5b7dd326c2 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTextModeTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTextModeTest.php @@ -20,7 +20,7 @@ */ class MemcachedCacheTextModeTest extends MemcachedCacheTest { - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { $client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['binary_protocol' => false]); diff --git a/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php index cf0dde92b33f4..ff671bbaccc8e 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/NullCacheTest.php @@ -20,7 +20,7 @@ */ class NullCacheTest extends TestCase { - public function createCachePool() + public function createCachePool(): NullCache { return new NullCache(); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/PdoCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/PdoCacheTest.php index cac5373c9edb0..204211f06be2d 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/PdoCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/PdoCacheTest.php @@ -42,7 +42,7 @@ public static function tearDownAfterClass(): void @unlink(self::$dbFile); } - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new PdoCache('sqlite:'.self::$dbFile, 'ns', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/PdoDbalCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/PdoDbalCacheTest.php index 80c868b5cabb8..1629959b43434 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/PdoDbalCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/PdoDbalCacheTest.php @@ -43,7 +43,7 @@ public static function tearDownAfterClass(): void @unlink(self::$dbFile); } - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new PdoCache(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]), '', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php b/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php index 08a8459c62c4b..3afa0ecbcf31b 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/PhpArrayCacheWithFallbackTest.php @@ -50,7 +50,7 @@ protected function tearDown(): void } } - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new PhpArrayCache(self::$file, new FilesystemCache('php-array-fallback', $defaultLifetime)); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/PhpFilesCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/PhpFilesCacheTest.php index 2ee25a536ea48..9698689ac0161 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/PhpFilesCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/PhpFilesCacheTest.php @@ -24,12 +24,12 @@ class PhpFilesCacheTest extends CacheTestCase 'testDefaultLifeTime' => 'PhpFilesCache does not allow configuring a default lifetime.', ]; - public function createSimpleCache(): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new PhpFilesCache('sf-cache'); } - protected function isPruned(CacheInterface $cache, $name) + protected function isPruned(CacheInterface $cache, string $name): bool { $getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile'); $getFileMethod->setAccessible(true); diff --git a/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheTest.php index 365147d1d390b..53bf31d063b1e 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Cache\Tests\Simple; +use Psr\Cache\CacheItemPoolInterface; use Psr\SimpleCache\CacheInterface; use Symfony\Component\Cache\Simple\Psr6Cache; @@ -23,10 +24,10 @@ abstract class Psr6CacheTest extends CacheTestCase 'testPrune' => 'Psr6Cache just proxies', ]; - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new Psr6Cache($this->createCacheItemPool($defaultLifetime)); } - abstract protected function createCacheItemPool($defaultLifetime = 0); + abstract protected function createCacheItemPool(int $defaultLifetime = 0): CacheItemPoolInterface; } diff --git a/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithAdapterTest.php b/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithAdapterTest.php index e5c7a6a4c7e9a..5d8e8c65e42f5 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithAdapterTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Cache\Tests\Simple; +use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Adapter\FilesystemAdapter; /** @@ -19,7 +20,7 @@ */ class Psr6CacheWithAdapterTest extends Psr6CacheTest { - protected function createCacheItemPool($defaultLifetime = 0) + protected function createCacheItemPool(int $defaultLifetime = 0): CacheItemPoolInterface { return new FilesystemAdapter('', $defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithoutAdapterTest.php b/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithoutAdapterTest.php index f987d405396c6..ae0f4cf76029c 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithoutAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/Psr6CacheWithoutAdapterTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Cache\Tests\Simple; +use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Cache\Tests\Fixtures\ExternalAdapter; /** @@ -19,7 +20,7 @@ */ class Psr6CacheWithoutAdapterTest extends Psr6CacheTest { - protected function createCacheItemPool($defaultLifetime = 0) + protected function createCacheItemPool(int $defaultLifetime = 0): CacheItemPoolInterface { return new ExternalAdapter($defaultLifetime); } diff --git a/src/Symfony/Component/Cache/Tests/Simple/RedisCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/RedisCacheTest.php index b5792f3971c1d..61a9423978f6f 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/RedisCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/RedisCacheTest.php @@ -49,14 +49,14 @@ public function testCreateConnection() /** * @dataProvider provideFailedCreateConnection */ - public function testFailedCreateConnection($dsn) + public function testFailedCreateConnection(string $dsn) { $this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException'); $this->expectExceptionMessage('Redis connection failed'); RedisCache::createConnection($dsn); } - public function provideFailedCreateConnection() + public function provideFailedCreateConnection(): array { return [ ['redis://localhost:1234'], @@ -68,14 +68,14 @@ public function provideFailedCreateConnection() /** * @dataProvider provideInvalidCreateConnection */ - public function testInvalidCreateConnection($dsn) + public function testInvalidCreateConnection(string $dsn) { $this->expectException('Symfony\Component\Cache\Exception\InvalidArgumentException'); $this->expectExceptionMessage('Invalid Redis DSN'); RedisCache::createConnection($dsn); } - public function provideInvalidCreateConnection() + public function provideInvalidCreateConnection(): array { return [ ['foo://localhost'], diff --git a/src/Symfony/Component/Cache/Tests/Simple/TraceableCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/TraceableCacheTest.php index 21bd1eadbb186..142d437d0bd44 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/TraceableCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/TraceableCacheTest.php @@ -25,7 +25,7 @@ class TraceableCacheTest extends CacheTestCase 'testPrune' => 'TraceableCache just proxies', ]; - public function createSimpleCache($defaultLifetime = 0): CacheInterface + public function createSimpleCache(int $defaultLifetime = 0): CacheInterface { return new TraceableCache(new FilesystemCache('', $defaultLifetime)); } diff --git a/src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php b/src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php index 3b1e1128ba0d7..d9c3b91568429 100644 --- a/src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php +++ b/src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php @@ -13,7 +13,7 @@ trait PdoPruneableTrait { - protected function isPruned($cache, $name) + protected function isPruned($cache, string $name): bool { $o = new \ReflectionObject($cache); diff --git a/src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php b/src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php index 9c6ce3956b2ab..7f1544af5b41d 100644 --- a/src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php +++ b/src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php @@ -16,7 +16,7 @@ /** * Common assertions for TagAware adapters. * - * @method \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface createCachePool() Must be implemented by TestCase + * @method \Symfony\Component\Cache\Adapter\TagAwareAdapterInterface createCachePool(int $defaultLifetime = 0) Must be implemented by TestCase */ trait TagAwareTestTrait { diff --git a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php index 1b1c9a2b26721..a8aa2acaf37a2 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php @@ -119,7 +119,7 @@ public function __destruct() } } - private function generateItems(iterable $items, array &$keys) + private function generateItems(iterable $items, array &$keys): iterable { $f = $this->createCacheItem; diff --git a/src/Symfony/Component/Cache/Traits/AbstractTrait.php b/src/Symfony/Component/Cache/Traits/AbstractTrait.php index dc5c7ff0e1956..f9a1d8fdafa26 100644 --- a/src/Symfony/Component/Cache/Traits/AbstractTrait.php +++ b/src/Symfony/Component/Cache/Traits/AbstractTrait.php @@ -250,7 +250,7 @@ protected static function unserialize($value) } } - private function getId($key) + private function getId($key): string { if ($this->versioningIsEnabled && '' === $this->namespaceVersion) { $this->ids = []; diff --git a/src/Symfony/Component/Cache/Traits/ArrayTrait.php b/src/Symfony/Component/Cache/Traits/ArrayTrait.php index 54413be3dfc06..21872c515b423 100644 --- a/src/Symfony/Component/Cache/Traits/ArrayTrait.php +++ b/src/Symfony/Component/Cache/Traits/ArrayTrait.php @@ -113,7 +113,7 @@ public function reset() $this->clear(); } - private function generateItems(array $keys, float $now, callable $f) + private function generateItems(array $keys, float $now, callable $f): iterable { foreach ($keys as $i => $key) { if (!$isHit = isset($this->expiries[$key]) && ($this->expiries[$key] > $now || !$this->deleteItem($key))) { diff --git a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php index d7125bec9e0cd..baacefc15281a 100644 --- a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php @@ -289,7 +289,7 @@ class LazyValue { public $file; - public function __construct($file) + public function __construct(string $file) { $this->file = $file; } diff --git a/src/Symfony/Component/Cache/Traits/RedisTrait.php b/src/Symfony/Component/Cache/Traits/RedisTrait.php index 67b2dd4da85c1..56581ab5496c5 100644 --- a/src/Symfony/Component/Cache/Traits/RedisTrait.php +++ b/src/Symfony/Component/Cache/Traits/RedisTrait.php @@ -423,7 +423,7 @@ protected function doSave(array $values, $lifetime) return $failed; } - private function pipeline(\Closure $generator) + private function pipeline(\Closure $generator): \Generator { $ids = [];