8000 minor #33508 [Cache] Add types to constructors and private/final/inte… · symfony/symfony@312cbf9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 312cbf9

Browse files
minor #33508 [Cache] Add types to constructors and private/final/internal methods (derrabus)
This PR was merged into the 4.4 branch. Discussion ---------- [Cache] Add types to constructors and private/final/internal methods | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179, #33228 | License | MIT | Doc PR | N/A I'm currently preparing a large PR collecting changes like these. However, the changeset for the Cache component was large enough to justify a dedicated PR, imho. Commits ------- 919afd2 [Cache] Add types to constructors and private/final/internal methods.
2 parents 81ac674 + 919afd2 commit 312cbf9

File tree

63 files changed

+111
-160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+111
-160
lines changed

src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private function generateItems(iterable $items)
260260
}
261261
}
262262

263-
private function getId($key)
263+
private function getId($key): string
264264
{
265265
CacheItem::validateKey($key);
266266

src/Symfony/Component/Cache/CacheItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static function validateKey($key): string
185185
*
186186
* @internal
187187
*/
188-
public static function log(LoggerInterface $logger = null, $message, $context = [])
188+
public static function log(?LoggerInterface $logger, string $message, array $context = [])
189189
{
190190
if ($logger) {
191191
$logger->warning($message, $context);

src/Symfony/Component/Cache/LockRegistry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public static function compute(callable $callback, ItemInterface $item, bool &$s
131131
$logger && $logger->info('Item "{key}" not found while lock was released, now retrying', ['key' => $item->getKey()]);
132132
}
133133
}
134+
135+
return null;
134136
}
135137

136138
private static function open(int $key)

src/Symfony/Component/Cache/Simple/AbstractCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private function normalizeTtl($ttl)
177177
throw new InvalidArgumentException(sprintf('Expiration date must be an integer, a DateInterval or null, "%s" given', \is_object($ttl) ? \get_class($ttl) : \gettype($ttl)));
178178
}
179179

180-
private function generateValues(iterable $values, array &$keys, $default)
180+
private function generateValues(iterable $values, array &$keys, $default): iterable
181181
{
182182
try {
183183
foreach ($values as $id => $value) {

src/Symfony/Component/Cache/Simple/ChainCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function getMultiple($keys, $default = null)
9292
return $this->generateItems($this->caches[0]->getMultiple($keys, $miss), 0, $miss, $default);
9393
}
9494

95-
private function generateItems(iterable $values, int $cacheIndex, $miss, $default)
95+
private function generateItems(iterable $values, int $cacheIndex, $miss, $default): iterable
9696
{
9797
$missing = [];
9898
$nextCacheIndex = $cacheIndex + 1;

src/Symfony/Component/Cache/Simple/PhpArrayCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function setMultiple($values, $ttl = null)
229229
return $saved;
230230
}
231231

232-
private function generateItems(array $keys, $default)
232+
private function generateItems(array $keys, $default): iterable
233233
{
234234
$fallbackKeys = [];
235235

src/Symfony/Component/Cache/Simple/TraceableCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function getCalls()
236236
}
237237
}
238238

239-
private function start(string $name)
239+
private function start(string $name): TraceableCacheEvent
240240
{
241241
$this->calls[] = $event = new TraceableCacheEvent();
242242
$event->name = $name;

src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ abstract class AbstractRedisAdapterTest extends AdapterTestCase
2424

2525
protected static $redis;
2626

27-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
27+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2828
{
2929
return new RedisAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);
3030
}

src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ApcuAdapterTest extends AdapterTestCase
2323
'testDefaultLifeTime' => 'Testing expiration slows down the test suite',
2424
];
2525

26-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
26+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2727
{
2828
if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN)) {
2929
$this->markTestSkipped('APCu extension is required.');

src/Symfony/Component/Cache/Tests/Adapter/ArrayAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ArrayAdapterTest extends AdapterTestCase
2525
'testSaveWithoutExpire' => 'Assumes a shared cache which ArrayAdapter is not.',
2626
];
2727

28-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
28+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2929
{
3030
return new ArrayAdapter($defaultLifetime);
3131
}

src/Symfony/Component/Cache/Tests/Adapter/ChainAdapterTest.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14-
use PHPUnit\Framework\MockObject\MockObject;
1514
use Psr\Cache\CacheItemPoolInterface;
1615
use Symfony\Component\Cache\Adapter\AdapterInterface;
1716
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -26,7 +25,7 @@
2625
*/
2726
class ChainAdapterTest extends AdapterTestCase
2827
{
29-
public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface
28+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
3029
{
3130
if ('testGetMetadata' === $testMethod) {
3231
return new ChainAdapter([new FilesystemAdapter('', $defaultLifetime)], $defaultLifetime);
@@ -70,14 +69,9 @@ public function testPrune()
7069
$this->assertFalse($cache->prune());
7170
}
7271

73-
/**
74-
* @return MockObject|PruneableCacheInterface
75-
*/
76-
private function getPruneableMock()
72+
private function getPruneableMock(): AdapterInterface
7773
{
78-
$pruneable = $this
79-
->getMockBuilder(PruneableCacheInterface::class)
80-
->getMock();
74+
$pruneable = $this->createMock([PruneableInterface::class, AdapterInterface::class]);
8175

8276
$pruneable
8377
->expects($this->atLeastOnce())
@@ -87,14 +81,9 @@ private function getPruneableMock()
8781
return $pruneable;
8882
}
8983

90-
/**
91-
* @return MockObject|PruneableCacheInterface
92-
*/
93-
private function getFailingPruneableMock()
84+
private function getFailingPruneableMock(): AdapterInterface
9485
{
95-
$pruneable = $this
96-
->getMockBuilder(PruneableCacheInterface::class)
97-
->getMock();
86+
$pruneable = $this->createMock([PruneableInterface::class, AdapterInterface::class]);
9887

9988
$pruneable
10089
->expects($this->atLeastOnce())
@@ -104,17 +93,8 @@ private function getFailingPruneableMock()
10493
return $pruneable;
10594
}
10695

107-
/**
108-
* @return MockObject|AdapterInterface
109-
*/
110-
private function getNonPruneableMock()
96+
private function getNonPruneableMock(): AdapterInterface
11197
{
112-
return $this
113-
->getMockBuilder(AdapterInterface::class)
114-
->getMock();
98+
return $this->createMock(AdapterInterface::class);
11599
}
116100
}
117-
118-
interface PruneableCacheInterface extends PruneableInterface, AdapterInterface
119-
{
120-
}

src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DoctrineAdapterTest extends AdapterTestCase
2727
'testClearPrefix' => 'Doctrine cannot clear by prefix',
2828
];
2929

30-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
30+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
3131
{
3232
return new DoctrineAdapter(new ArrayCache($defaultLifetime), '', $defaultLifetime);
3333
}

src/Symfony/Component/Cache/Tests/Adapter/FilesystemAdapterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class FilesystemAdapterTest extends AdapterTestCase
2121
{
22-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
22+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2323
{
2424
return new FilesystemAdapter('', $defaultLifetime);
2525
}
@@ -29,7 +29,7 @@ public static function tearDownAfterClass(): void
2929
self::rmdir(sys_get_temp_dir().'/symfony-cache');
3030
}
3131

32-
public static function rmdir($dir)
32+
public static function rmdir(string $dir)
3333
{
3434
if (!file_exists($dir)) {
3535
return;
@@ -51,7 +51,7 @@ public static function rmdir($dir)
5151
rmdir($dir);
5252
}
5353

54-
protected function isPruned(CacheItemPoolInterface $cache, $name)
54+
protected function isPruned(CacheItemPoolInterface $cache, string $name): bool
5555
{
5656
$getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');
5757
$getFileMethod->setAccessible(true);

src/Symfony/Component/Cache/Tests/Adapter/FilesystemTagAwareAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FilesystemTagAwareAdapterTest extends FilesystemAdapterTest
2222
{
2323
use TagAwareTestTrait;
2424

25-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
25+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2626
{
2727
return new FilesystemTagAwareAdapter('', $defaultLifetime);
2828
}

src/Symfony/Component/Cache/Tests/Adapter/MaxIdLengthAdapterTest.php

Line F438 s changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ abstract class MaxIdLengthAdapter extends AbstractAdapter
8080
{
8181
protected $maxIdLength = 50;
8282

83-
public function __construct($ns)
83+
public function __construct(string $ns)
8484
{
8585
parent::__construct($ns);
8686
}

src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static function setUpBeforeClass(): void
3939
}
4040
}
4141

42-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
42+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
4343
{
4444
$client = $defaultLifetime ? AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST')) : self::$client;
4545

@@ -73,7 +73,7 @@ public function testBadOptions($name, $value)
7373
MemcachedAdapter::createConnection([], [$name => $value]);
7474
}
7575

76-
public function provideBadOptions()
76+
public function provideBadOptions(): array
7777
{
7878
return [
7979
['foo', 'bar'],
@@ -109,7 +109,7 @@ public function testOptionSerializer()
109109
/**
110110
* @dataProvider provideServersSetting
111111
*/< 10000 /span>
112-
public function testServersSetting($dsn, $host, $port)
112+
public function testServersSetting(string $dsn, string $host, int $port)
113113
{
114114
$client1 = MemcachedAdapter::createConnection($dsn);
115115
$client2 = MemcachedAdapter::createConnection([$dsn]);
@@ -125,7 +125,7 @@ public function testServersSetting($dsn, $host, $port)
125125
$this->assertSame([$expect], array_map($f, $client3->getServerList()));
126126
}
127127

128-
public function provideServersSetting()
128+
public function provideServersSetting(): iterable
129129
{
130130
yield [
131131
'memcached://127.0.0.1/50',
@@ -166,7 +166,7 @@ public function provideServersSetting()
166166
/**
167167
* @dataProvider provideDsnWithOptions
168168
*/
169-
public function testDsnWithOptions($dsn, array $options, array $expectedOptions)
169+
public function testDsnWithOptions(string $dsn, array $options, array $expectedOptions)
170170
{
171171
$client = MemcachedAdapter::createConnection($dsn, $options);
172172

@@ -175,7 +175,7 @@ public function testDsnWithOptions($dsn, array $options, array $expectedOptions)
175175
}
176176
}
177177

178-
public function provideDsnWithOptions()
178+
public function provideDsnWithOptions(): iterable
179179
{
180180
if (!class_exists('\Memcached')) {
181181
self::markTestSkipped('Extension memcached required.');

src/Symfony/Component/Cache/Tests/Adapter/NamespacedProxyAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
class NamespacedProxyAdapterTest extends ProxyAdapterTest
2323
{
24-
public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface
24+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
2525
{
2626
if ('testGetMetadata' === $testMethod) {
2727
return new ProxyAdapter(new FilesystemAdapter(), 'foo', $defaultLifetime);

src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function tearDownAfterClass(): void
4141
@unlink(self::$dbFile);
4242
}
4343

44-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
44+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
4545
{
4646
return new PdoAdapter('sqlite:'.self::$dbFile, 'ns', $defaultLifetime);
4747
}

src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static function tearDownAfterClass(): void
4141
@unlink(self::$dbFile);
4242
}
4343

44-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
44+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
4545
{
4646
return new PdoAdapter(DriverManager::getConnection(['driver' => 'pdo_sqlite', 'path' => self::$dbFile]), '', $defaultLifetime);
4747
}

src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function tearDown(): void
7171
}
7272
}
7373

74-
public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface
74+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
7575
{
7676
if ('testGetMetadata' === $testMethod || 'testClearPrefix' === $testMethod) {
7777
return new PhpArrayAdapter(self::$file, new FilesystemAdapter());

src/Symfony/Component/Cache/Tests/Adapter/PhpArrayAdapterWithFallbackTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function tearDown(): void
4343
}
4444
}
4545

46-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
46+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
4747
{
4848
return new PhpArrayAdapter(self::$file, new FilesystemAdapter('php-array-fallback', $defaultLifetime));
4949
}

src/Symfony/Component/Cache/Tests/Adapter/PhpFilesAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function tearDownAfterClass(): void
3333
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
3434
}
3535

36-
protected function isPruned(CacheItemPoolInterface $cache, $name)
36+
protected function isPruned(CacheItemPoolInterface $cache, string $name): bool
3737
{
3838
$getFileMethod = (new \ReflectionObject($cache))->getMethod('getFile');
3939
$getFileMethod->setAccessible(true);

src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function setUp(): void
2525
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
2626
}
2727

28-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
28+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2929
{
3030
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
3131
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);

src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareClusterAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function setUp(): void
2525
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
2626
}
2727

28-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
28+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2929
{
3030
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
3131
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);

src/Symfony/Component/Cache/Tests/Adapter/PredisTagAwareRedisClusterAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function setUp(): void
2525
$this->skippedTests['testTagItemExpiry'] = 'Testing expiration slows down the test suite';
2626
}
2727

28-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
28+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
2929
{
3030
$this->assertInstanceOf(\Predis\Client::class, self::$redis);
3131
$adapter = new RedisTagAwareAdapter(self::$redis, str_replace('\\', '.', __CLASS__), $defaultLifetime);

src/Symfony/Component/Cache/Tests/Adapter/ProxyAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ProxyAdapterTest extends AdapterTestCase
2929
'testPrune' => 'ProxyAdapter just proxies',
3030
];
3131

32-
public function createCachePool($defaultLifetime = 0, $testMethod = null): CacheItemPoolInterface
32+
public function createCachePool(int $defaultLifetime = 0, string $testMethod = null): CacheItemPoolInterface
3333
{
3434
if ('testGetMetadata' === $testMethod) {
3535
return new ProxyAdapter(new FilesystemAdapter(), '', $defaultLifetime);

src/Symfony/Component/Cache/Tests/Adapter/Psr16AdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Psr16AdapterTest extends AdapterTestCase
2727
'testClearPrefix' => 'SimpleCache cannot clear by prefix',
2828
];
2929

30-
public function createCachePool($defaultLifetime = 0): CacheItemPoolInterface
30+
public function createCachePool(int $defaultLifetime = 0): CacheItemPoolInterface
3131
{
3232
return new Psr16Adapter(new Psr16Cache(new FilesystemAdapter()), '', $defaultLifetime);
3333
}

0 commit comments

Comments
 (0)
0