Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add return types - batch 1/n #42504

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 1 commit into from
Aug 13, 2021
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
4 changes: 1 addition & 3 deletions src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ static function ($deferred, $namespace, &$expiredIds, $getId, $defaultLifetime)
* Returns the best possible adapter that your runtime supports.
*
* Using ApcuAdapter makes system caches compatible with read-only filesystems.
*
* @return AdapterInterface
*/
public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null)
public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null): AdapterInterface
{
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory, true);
if (null !== $logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ abstract protected function doSave(array $values, int $lifetime, array $addTagDa
*
* @return bool True if the items were successfully removed, false otherwise
*/
abstract protected function doDelete(array $ids);
abstract protected function doDelete(array $ids): bool;

/**
* Removes relations between tags and deleted items.
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function isSupported()
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
try {
Expand All @@ -77,15 +77,15 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
return apcu_exists($id);
}

/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
return isset($namespace[0]) && class_exists(\APCuIterator::class, 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 @@ -95,7 +95,7 @@ protected function doClear(string $namespace)
/**
* {@inheritdoc}
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
foreach ($ids as $id) {
apcu_delete($id);
Expand All @@ -107,7 +107,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
if (null !== $this->marshaller && (!$values = $this->marshaller->marshall($values, $failed))) {
return $failed;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public function commit(): bool
/**
* {@inheritdoc}
*/
public function prune()
public function prune(): bool
{
$pruned = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private static function initOptions(array $options): array
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
$resultsCouchbase = $this->bucket->get($ids);

Expand Down Expand Up @@ -218,7 +218,7 @@ protected function doDelete(array $ids): bool
/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
if (!$values = $this->marshaller->marshall($values, $failed)) {
return $failed;
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Cache/Adapter/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function reset()
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
$unserializeCallbackHandler = ini_set('unserialize_callback_func', parent::class.'::handleUnserializeCallback');
try {
Expand All @@ -65,15 +65,15 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
return $this->provider->contains($id);
}

/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
$namespace = $this->provider->getNamespace();

Expand All @@ -85,7 +85,7 @@ protected function doClear(string $namespace)
/**
* {@inheritdoc}
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
$ok = true;
foreach ($ids as $id) {
Expand All @@ -98,7 +98,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
return $this->provider->saveMultiple($values, $lifetime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(string $namespace = '', int $defaultLifetime = 0, st
/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
$ok = $this->doClearCache($namespace);

Expand Down
14 changes: 6 additions & 8 deletions src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,9 @@ public static function isSupported()
* @param array[]|string|string[] $servers An array of servers, a DSN, or an array of DSNs
* @param array $options An array of options
*
* @return \Memcached
*
* @throws \ErrorException When invalid options or servers are provided
*/
public static function createConnection(array|string $servers, array $options = [])
public static function createConnection(array|string $servers, array $options = []): \Memcached
{
if (\is_string($servers)) {
$servers = [$servers];
Expand Down Expand Up @@ -243,7 +241,7 @@ public static function createConnection(array|string $servers, array $options =
/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
if (!$values = $this->marshaller->marshall($values, $failed)) {
return $failed;
Expand All @@ -264,7 +262,7 @@ protected function doSave(array $values, int $lifetime)
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
try {
$encodedIds = array_map('self::encodeKey', $ids);
Expand All @@ -285,15 +283,15 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
}

/**
* {@inheritdoc}
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
$ok = true;
$encodedIds = array_map('self::encodeKey', $ids);
Expand All @@ -309,7 +307,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
return '' === $namespace && $this->getClient()->flush();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Cache/Adapter/PdoAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function configureSchema(Schema $schema, Connection $forConnection): void
/**
* {@inheritdoc}
*/
public function prune()
public function prune(): bool
{
$deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";

Expand Down Expand Up @@ -213,7 +213,7 @@ public function prune()
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
$now = time();
$expired = [];
Expand Down Expand Up @@ -257,7 +257,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
$stmt = $this->getConnection()->prepare($sql);
Expand All @@ -272,7 +272,7 @@ protected function doHave(string $id)
/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
$conn = $this->getConnection();

Expand Down Expand Up @@ -302,7 +302,7 @@ protected function doClear(string $namespace)
/**
* {@inheritdoc}
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
$sql = str_pad('', (\count($ids) << 1) - 1, '?,');
$sql = "DELETE FROM $this->table WHERE $this->idCol IN ($sql)";
Expand All @@ -319,7 +319,7 @@ protected function doDelete(array $ids)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
if (!$values = $this->marshaller->marshall($values, $failed)) {
return $failed;
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ static function ($key, $value, $isHit) {
*
* @param string $file The PHP file were values are cached
* @param CacheItemPoolInterface $fallbackPool A pool to fallback on when an item is not hit
*
* @return CacheItemPoolInterface
*/
public static function create(string $file, CacheItemPoolInterface $fallbackPool)
public static function create(string $file, CacheItemPoolInterface $fallbackPool): CacheItemPoolInterface
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static function create(string $file, CacheItemPoolInterface $fallbackPool): CacheItemPoolInterface
public static function create(string $file, CacheItemPoolInterface $fallbackPool): static

I don't quite understand why the previously annotated return type was so wide, tbh.

{
if (!$fallbackPool instanceof AdapterInterface) {
$fallbackPool = new ProxyAdapter($fallbackPool);
Expand Down
15 changes: 6 additions & 9 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ public static function isSupported()
return \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOLEAN));
}

/**
* @return bool
*/
public function prune()
public function prune(): bool
{
$time = time();
$pruned = true;
Expand Down Expand Up @@ -95,7 +92,7 @@ public function prune()
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
if ($this->appendOnly) {
$now = 0;
Expand Down Expand Up @@ -171,7 +168,7 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
if ($this->appendOnly && isset($this->values[$id])) {
return true;
Expand Down Expand Up @@ -211,7 +208,7 @@ protected function doHave(string $id)
/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
$ok = true;
$expiry = $lifetime ? time() + $lifetime : 'PHP_INT_MAX';
Expand Down Expand Up @@ -273,7 +270,7 @@ protected function doSave(array $values, int $lifetime)
/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
$this->values = [];

Expand All @@ -283,7 +280,7 @@ protected function doClear(string $namespace)
/**
* {@inheritdoc}
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
foreach ($ids as $id) {
unset($this->values[$id]);
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Cache/Adapter/Psr16Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(CacheInterface $pool, string $namespace = '', int $d
/**
* {@inheritdoc}
*/
protected function doFetch(array $ids)
protected function doFetch(array $ids): iterable
{
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
if ($this->miss !== $value) {
Expand All @@ -55,31 +55,31 @@ protected function doFetch(array $ids)
/**
* {@inheritdoc}
*/
protected function doHave(string $id)
protected function doHave(string $id): bool
{
return $this->pool->has($id);
}

/**
* {@inheritdoc}
*/
protected function doClear(string $namespace)
protected function doClear(string $namespace): bool
{
return $this->pool->clear();
}

/**
* {@inheritdoc}
*/
protected function doDelete(array $ids)
protected function doDelete(array $ids): bool
{
return $this->pool->deleteMultiple($ids);
}

/**
* {@inheritdoc}
*/
protected function doSave(array $values, int $lifetime)
protected function doSave(array $values, int $lifetime): array|bool
{
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,7 @@ public function commit(): bool
return $this->invalidateTags([]);
}

/**
* @return array
*/
public function __sleep()
public function __sleep(): array
{
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/TraceableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function commit(): bool
/**
* {@inheritdoc}
*/
public function prune()
public function prune(): bool
{
if (!$this->pool instanceof PruneableInterface) {
return false;
Expand Down
Loading