8000 [Cache] [5.0] add type hint to cache · symfony/symfony@0a41f6c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a41f6c

Browse files
committed
[Cache] [5.0] add type hint to cache
1 parent 38b9b95 commit 0a41f6c

14 files changed

+25
-28
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function ($deferred, $namespace, &$expiredIds) use ($getId) {
107107
*
108108
* @return AdapterInterface
109109
*/
110-
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
110+
public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null)
111111
{
112112
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory, true);
113113
if (null !== $logger) {
@@ -118,7 +118,7 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
118118
return $opcache;
119119
}
120120

121-
$apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version);
121+
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $version);
122122
if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
123123
$apcu->setLogger(new NullLogger());
124124
} elseif (null !== $logger) {
@@ -128,11 +128,8 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
128128
return new ChainAdapter([$apcu, $opcache]);
129129
}
130130

131-
public static function createConnection($dsn, array $options = [])
131+
public static function createConnection(string $dsn, array $options = [])
132132
{
133-
if (!\is_string($dsn)) {
134-
throw new InvalidArgumentException(sprintf('The %s() method expect argument #1 to be string, %s given.', __METHOD__, \gettype($dsn)));
135-
}
136133
if (0 === strpos($dsn, 'redis:') || 0 === strpos($dsn, 'rediss:')) {
137134
return RedisAdapter::createConnection($dsn, $options);
138135
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function doHave($id)
8080
/**
8181
* {@inheritdoc}
8282
*/
83-
protected function doClear($namespace)
83+
protected function doClear(string $namespace)
8484
{
8585
return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== \PHP_SAPI || filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))
8686
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
@@ -102,7 +102,7 @@ protected function doDelete(array $ids)
102102
/**
103103
* {@inheritdoc}
104104
*/
105-
protected function doSave(array $values, $lifetime)
105+
protected function doSave(array $values, int $lifetime)
106106
{
107107
try {
108108
if (false === $failures = apcu_store($values, null, $lifetime)) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function doHave($id)
7373
/**
7474
* {@inheritdoc}
7575
*/
76-
protected function doClear($namespace)
76+
protected function doClear(string $namespace)
7777
{
7878
$namespace = $this->provider->getNamespace();
7979

@@ -98,7 +98,7 @@ protected function doDelete(array $ids)
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
protected function doSave(array $values, $lifetime)
101+
protected function doSave(array $values, int $lifetime)
102102
{
103103
return $this->provider->saveMultiple($values, $lifetime);
104104
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public static function createConnection($servers, array $options = [])
234234
/**
235235
* {@inheritdoc}
236236
*/
237-
protected function doSave(array $values, $lifetime)
237+
protected function doSave(array $values, int $lifetime)
238238
{
239239
if (!$values = $this->marshaller->marshall($values, $failed)) {
240240
return $failed;
@@ -300,7 +300,7 @@ protected function doDelete(array $ids)
300300
/**
301301
* {@inheritdoc}
302302
*/
303-
protected function doClear($namespace)
303+
protected function doClear(string $namespace)
304304
{
305305
return '' === $namespace && $this->getClient()->flush();
306306
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ protected function doHave($id)
251251
/**
252252
* {@inheritdoc}
253253
*/
254-
protected function doClear($namespace)
254+
protected function doClear(string $namespace)
255255
{
256256
$conn = $this->getConnection();
257257

@@ -292,7 +292,7 @@ protected function doDelete(array $ids)
292292
/**
293293
* {@inheritdoc}
294294
*/
295-
protected function doSave(array $values, $lifetime)
295+
protected function doSave(array $values, int $lifetime)
296296
{
297297
if (!$values = $this->marshaller->marshall($values, $failed)) {
298298
return $failed;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected function doHave($id)
199199
/**
200200
* {@inheritdoc}
201201
*/
202-
protected function doSave(array $values, $lifetime)
202+
protected function doSave(array $values, int $lifetime)
203203
{
204204
$ok = true;
205205
$expiry = $lifetime ? time() + $lifetime : 'PHP_INT_MAX';
@@ -256,7 +256,7 @@ protected function doSave(array $values, $lifetime)
256256
/**
257257
* {@inheritdoc}
258258
*/
259-
protected function doClear($namespace)
259+
protected function doClear(string $namespace)
260260
{
261261
$this->values = [];
262262

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function doHave($id)
6363
/**
6464
* {@inheritdoc}
6565
*/
66-
protected function doClear($namespace)
66+
protected function doClear(string $namespace)
6767
{
6868
return $this->pool->clear();
6969
}
@@ -79,7 +79,7 @@ protected function doDelete(array $ids)
7979
/**
8080
* {@inheritdoc}
8181
*/
82-
protected function doSave(array $values, $lifetime)
82+
protected function doSave(array $values, int $lifetime)
8383
{
8484
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
8585
}

src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
3333
* @param string $name
3434
* @param TraceableAdapter $instance
3535
*/
36-
public function addInstance($name, TraceableAdapter $instance)
36+
public function addInstance(string $name, TraceableAdapter $instance)
3737
{
3838
$this->instances[$name] = $instance;
3939
}

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function process(ContainerBuilder $container)
148148
}
149149
}
150150

151-
private function getNamespace($seed, $id)
151+
private function getNamespace(string $seed, string $id)
152152
{
153153
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$seed, true))), 0, 10);
154154
}

src/Symfony/Component/Cache/Marshaller/DefaultMarshaller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function unmarshall(string $value)
9292
/**
9393
* @internal
9494
*/
95-
public static function handleUnserializeCallback($class)
95+
public static function handleUnserializeCallback(string $class)
9696
{
9797
throw new \DomainException('Class not found: '.$class);
9898
}

src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract protected function doFetch(array $ids);
6161
*
6262
* @return bool True if item exists in the cache, false otherwise
6363
*/
64-
abstract protected function doHave($id);
64+
abstract protected function doHave(string $id);
6565

6666
/**
6767
* Deletes all items in the pool.
@@ -70,7 +70,7 @@ abstract protected function doHave($id);
7070
*
7171
* @return bool True if the pool was successfully cleared, false otherwise
7272
*/
73-
abstract protected function doClear($namespace);
73+
abstract protected function doClear(string $namespace);
7474

7575
/**
7676
* Removes multiple items from the pool.
@@ -89,7 +89,7 @@ abstract protected function doDelete(array $ids);
8989
*
9090
* @return array|bool The identifiers that failed to be cached or a boolean stating if caching succeeded or not
9191
*/
92-
abstract protected function doSave(array $values, $lifetime);
92+
abstract protected function doSave(array $values, int $lifetime);
9393

9494
/**
9595
* {@inheritdoc}

src/Symfony/Component/Cache/Traits/FilesystemCommonTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ private function init($namespace, $directory)
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
protected function doClear($namespace)
54+
protected function doClear(string $namespace)
5555
{
5656
$ok = true;
5757

src/Symfony/Component/Cache/Traits/FilesystemTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function doHave($id)
9191
/**
9292
* {@inheritdoc}
9393
*/
94-
protected function doSave(array $values, $lifetime)
94+
protected function doSave(array $values, int $lifetime)
9595
{
9696
$expiresAt = $lifetime ? (time() + $lifetime) : 0;
9797
$values = $this->marshaller->marshall($values, $failed);

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ protected function doHave($id)
332332
/**
333333
* {@inheritdoc}
334334
*/
335-
protected function doClear($namespace)
335+
protected function doClear(string $namespace)
336336
{
337337
$cleared = true;
338338
if ($this->redis instanceof \Predis\Client) {
@@ -399,7 +399,7 @@ protected function doDelete(array $ids)
399399
/**
400400
* {@inheritdoc}
401401
*/
402-
protected function doSave(array $values, $lifetime)
402+
protected function doSave(array $values, int $lifetime)
403403
{
404404
if (!$values = $this->marshaller->marshall($values, $failed)) {
405405
return $failed;

0 commit comments

Comments
 (0)
0