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
}

0 commit comments

Comments
 (0)
0