8000 [Cache] [5.0] Add type-hint to the Cache component. by Simperfit · Pull Request #32282 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] [5.0] Add type-hint to the Cache component. #32282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function ($deferred, $namespace, &$expiredIds) use ($getId) {
*
* @return AdapterInterface
*/
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the param phpdoc should be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I also think the method should not be in AbstractAdapter. It get's inherited to all adapters. But it not meant to be overwritten or called with late static binding. It's a plain factory method, independent of all the adapters.

{
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory, true);
if (null !== $logger) {
Expand All @@ -118,7 +118,7 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
return $opcache;
}

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

public static function createConnection($dsn, array $options = [])
public static function createConnection(string $dsn, array $options = [])
{
if (!\is_string($dsn)) {
throw new InvalidArgumentException(sprintf('The %s() method expect argument #1 to be string, %s given.', __METHOD__, \gettype($dsn)));
}
if (0 === strpos($dsn, 'redis:') || 0 === strpos($dsn, 'rediss:')) {
return RedisAdapter::createConnection($dsn, $options);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== \PHP_SAPI || filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
Expand All @@ -102,7 +102,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
try {
if (false === $failures = apcu_store($values, null, $lifetime)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
$namespace = $this->provider->getNamespace();

Expand All @@ -98,7 +98,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
return $this->provider->saveMultiple($values, $lifetime);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static function createConnection($servers, array $options = [])
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
if (!$values = $this->marshaller->marshall($values, $failed)) {
return $failed;
Expand Down Expand Up @@ -300,7 +300,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
return '' === $namespace && $this->getClient()->flush();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
$conn = $this->getConnection();

Expand Down Expand Up @@ -292,7 +292,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
if (!$values = $this->marshaller->marshall($values, $failed)) {
return $failed;
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
$ok = true;
$expiry = $lifetime ? time() + $lifetime : 'PHP_INT_MAX';
Expand Down Expand Up @@ -256,7 +256,7 @@ protected function doSave(array $values, $lifetime)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
$this->values = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/Psr16Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
return $this->pool->clear();
}
Expand All @@ -79,7 +79,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CacheDataCollector extends DataCollector implements LateDataCollectorInter
* @param string $name
* @param TraceableAdapter $instance
*/
public function addInstance($name, TraceableAdapter $instance)
public function addInstance(string $name, TraceableAdapter $instance)
{
$this->instances[$name] = $instance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function process(ContainerBuilder $container)
}
}

private function getNamespace($seed, $id)
private function getNamespace(string $seed, string $id)
{
return substr(str_replace('/', '-', base64_encode(hash('sha256', $id.$seed, true))), 0, 10);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function unmarshall(string $value)
/**
* @internal
*/
public static function handleUnserializeCallback($class)
public static function handleUnserializeCallback(string $class)
{
throw new \DomainException('Class not found: '.$class);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ abstract protected function doFetch(array $ids);
*
* @return bool True if item exists in the cache, false otherwise
*/
abstract protected function doHave($id);
abstract protected function doHave(string $id);

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

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

/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private function init($namespace, $directory)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
$ok = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Traits/FilesystemTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
$expiresAt = $lifetime ? (time() + $lifetime) : 0;
$values = $this->marshaller->marshall($values, $failed);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected function doHave($id)
/**
* {@inheritdoc}
*/
protected function doClear($namespace)
protected function doClear(string $namespace)
{
$cleared = true;
if ($this->redis instanceof \Predis\Client) {
Expand Down Expand Up @@ -399,7 +399,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, $lifetime)
protected function doSave(array $values, int $lifetime)
{
if (!$values = $this->marshaller->marshall($values, $failed)) {
return $failed;
Expand Down
0