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

Skip to content

Commit da0ad85

Browse files
minor #42504 Add return types - batch 1/n (nicolas-grekas)
This PR was merged into the 6.0 branch. Discussion ---------- Add return types - batch 1/n | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | #40154 | License | MIT | Doc PR | - Extracted from #42496 for components that shouldn't be extended very often. Commits ------- 1564887 Add return types - batch 1/n
2 parents 7d2820c + 1564887 commit da0ad85

File tree

84 files changed

+327
-380
lines changed

Some content is hidden

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

84 files changed

+327
-380
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ static function ($deferred, $namespace, &$expiredIds, $getId, $defaultLifetime)
9898
* Returns the best possible adapter that your runtime supports.
9999
*
100100
* Using ApcuAdapter makes system caches compatible with read-only filesystems.
101-
*
102-
* @return AdapterInterface
103101
*/
104-
public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null)
102+
public static function createSystemCache(string $namespace, int $defaultLifetime, string $version, string $directory, LoggerInterface $logger = null): AdapterInterface
105103
{
106104
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory, true);
107105
if (null !== $logger) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ abstract protected function doSave(array $values, int $lifetime, array $addTagDa
138138
*
139139
* @return bool True if the items were successfully removed, false otherwise
140140
*/
141-
abstract protected function doDelete(array $ids);
141+
abstract protected function doDelete(array $ids): bool;
142142

143143
/**
144144
* Removes relations between tags and deleted items.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static function isSupported()
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
protected function doFetch(array $ids)
58+
protected function doFetch(array $ids): iterable
5959
{
6060
$unserializeCallbackHandler = ini_set('unserialize_callback_func', __CLASS__.'::handleUnserializeCallback');
6161
try {
@@ -77,15 +77,15 @@ protected function doFetch(array $ids)
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
protected function doHave(string $id)
80+
protected function doHave(string $id): bool
8181
{
8282
return apcu_exists($id);
8383
}
8484

8585
/**
8686
* {@inheritdoc}
8787
*/
88-
protected function doClear(string $namespace)
88+
protected function doClear(string $namespace): bool
8989
{
9090
return isset($namespace[0]) && class_exists(\APCuIterator::class, false) && ('cli' !== \PHP_SAPI || filter_var(ini_get('apc.enable_cli'), \FILTER_VALIDATE_BOOLEAN))
9191
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), \APC_ITER_KEY))
@@ -95,7 +95,7 @@ protected function doClear(string $namespace)
9595
/**
9696
* {@inheritdoc}
9797
*/
98-
protected function doDelete(array $ids)
98+
protected function doDelete(array $ids): bool
9999
{
100100
foreach ($ids as $id) {
101101
apcu_delete($id);
@@ -107,7 +107,7 @@ protected function doDelete(array $ids)
107107
/**
108108
* {@inheritdoc}
109109
*/
110-
protected function doSave(array $values, int $lifetime)
110+
protected function doSave(array $values, int $lifetime): array|bool
111111
{
112112
if (null !== $this->marshaller && (!$values = $this->marshaller->marshall($values, $failed))) {
113113
return $failed;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function commit(): bool
292292
/**
293293
* {@inheritdoc}
294294
*/
295-
public function prune()
295+
public function prune(): bool
296296
{
297297
$pruned = true;
298298

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ private static function initOptions(array $options): array
161161
/**
162162
* {@inheritdoc}
163163
*/
164-
protected function doFetch(array $ids)
164+
protected function doFetch(array $ids): iterable
165165
{
166166
$resultsCouchbase = $this->bucket->get($ids);
167167

@@ -218,7 +218,7 @@ protected function doDelete(array $ids): bool
218218
/**
219219
* {@inheritdoc}
220220
*/
221-
protected function doSave(array $values, int $lifetime)
221+
protected function doSave(array $values, int $lifetime): array|bool
222222
{
223223
if (!$values = $this->marshaller->marshall($values, $failed)) {
224224
return $failed;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function reset()
3939
/**
4040
* {@inheritdoc}
4141
*/
42-
protected function doFetch(array $ids)
42+
protected function doFetch(array $ids): iterable
4343
{
4444
$unserializeCallbackHandler = ini_set('unserialize_callback_func', parent::class.'::handleUnserializeCallback');
4545
try {
@@ -65,15 +65,15 @@ protected function doFetch(array $ids)
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
protected function doHave(string $id)
68+
protected function doHave(string $id): bool
6969
{
7070
return $this->provider->contains($id);
7171
}
7272

7373
/**
7474
* {@inheritdoc}
7575
*/
76-
protected function doClear(string $namespace)
76+
protected function doClear(string $namespace): bool
7777
{
7878
$namespace = $this->provider->getNamespace();
7979

@@ -85,7 +85,7 @@ protected function doClear(string $namespace)
8585
/**
8686
* {@inheritdoc}
8787
*/
88-
protected function doDelete(array $ids)
88+
protected function doDelete(array $ids): bool
8989
{
9090
$ok = true;
9191
foreach ($ids as $id) {
@@ -98,7 +98,7 @@ protected function doDelete(array $ids)
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
protected function doSave(array $values, int $lifetime)
101+
protected function doSave(array $values, int $lifetime): array|bool
102102
{
103103
return $this->provider->saveMultiple($values, $lifetime);
104104
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(string $namespace = '', int $defaultLifetime = 0, st
4444
/**
4545
* {@inheritdoc}
4646
*/
47-
protected function doClear(string $namespace)
47+
protected function doClear(string $namespace): bool
4848
{
4949
$ok = $this->doClearCache($namespace);
5050

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ public static function isSupported()
9292
* @param array[]|string|string[] $servers An array of servers, a DSN, or an array of DSNs
9393
* @param array $options An array of options
9494
*
95-
* @return \Memcached
96-
*
9795
* @throws \ErrorException When invalid options or servers are provided
9896
*/
99-
public static function createConnection(array|string $servers, array $options = [])
97+
public static function createConnection(array|string $servers, array $options = []): \Memcached
10098
{
10199
if (\is_string($servers)) {
102100
$servers = [$servers];
@@ -243,7 +241,7 @@ public static function createConnection(array|string $servers, array $options =
243241
/**
244242
* {@inheritdoc}
245243
*/
246-
protected function doSave(array $values, int $lifetime)
244+
protected function doSave(array $values, int $lifetime): array|bool
247245
{
248246
if (!$values = $this->marshaller->marshall($values, $failed)) {
249247
return $failed;
@@ -264,7 +262,7 @@ protected function doSave(array $values, int $lifetime)
264262
/**
265263
* {@inheritdoc}
266264
*/
267-
protected function doFetch(array $ids)
265+
protected function doFetch(array $ids): iterable
268266
{
269267
try {
270268
$encodedIds = array_map('self::encodeKey', $ids);
@@ -285,15 +283,15 @@ protected function doFetch(array $ids)
285283
/**
286284
* {@inheritdoc}
287285
*/
288-
protected function doHave(string $id)
286+
protected function doHave(string $id): bool
289287
{
290288
return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
291289
}
292290

293291
/**
294292
* {@inheritdoc}
295293
*/
296-
protected function doDelete(array $ids)
294+
protected function doDelete(array $ids): bool
297295
{
298296
$ok = true;
299297
$encodedIds = array_map('self::encodeKey', $ids);
@@ -309,7 +307,7 @@ protected function doDelete(array $ids)
309307
/**
310308
* {@inheritdoc}
311309
*/
312-
protected function doClear(string $namespace)
310+
protected function doClear(string $namespace): bool
313311
{
314312
return '' === $namespace && $this->getClient()->flush();
315313
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function configureSchema(Schema $schema, Connection $forConnection): void
181181
/**
182182
* {@inheritdoc}
183183
*/
184-
public function prune()
184+
public function prune(): bool
185185
{
186186
$deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time";
187187

@@ -213,7 +213,7 @@ public function prune()
213213
/**
214214
* {@inheritdoc}
215215
*/
216-
protected function doFetch(array $ids)
216+
protected function doFetch(array $ids): iterable
217217
{
218218
$now = time();
219219
$expired = [];
@@ -257,7 +257,7 @@ protected function doFetch(array $ids)
257257
/**
258258
* {@inheritdoc}
259259
*/
260-
protected function doHave(string $id)
260+
protected function doHave(string $id): bool
261261
{
262262
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
263263
$stmt = $this->getConnection()->prepare($sql);
@@ -272,7 +272,7 @@ protected function doHave(string $id)
272272
/**
273273
* {@inheritdoc}
274274
*/
275-
protected function doClear(string $namespace)
275+
protected function doClear(string $namespace): bool
276276
{
277277
$conn = $this->getConnection();
278278

@@ -302,7 +302,7 @@ protected function doClear(string $namespace)
302302
/**
303303
* {@inheritdoc}
304304
*/
305-
protected function doDelete(array $ids)
305+
protected function doDelete(array $ids): bool
306306
{
307307
$sql = str_pad('', (\count($ids) << 1) - 1, '?,');
308308
$sql = "DELETE FROM $this->table WHERE $this->idCol IN ($sql)";
@@ -319,7 +319,7 @@ protected function doDelete(array $ids)
319319
/**
320320
* {@inheritdoc}
321321
*/
322-
protected function doSave(array $values, int $lifetime)
322+
protected function doSave(array $values, int $lifetime): array|bool
323323
{
324324
if (!$values = $this->marshaller->marshall($values, $failed)) {
325325
return $failed;

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ static function ($key, $value, $isHit) {
6868
*
6969
* @param string $file The PHP file were values are cached
7070
* @param CacheItemPoolInterface $fallbackPool A pool to fallback on when an item is not hit
71-
*
72-
* @return CacheItemPoolInterface
7371
*/
74-
public static function create(string $file, CacheItemPoolInterface $fallbackPool)
72+
public static function create(string $file, CacheItemPoolInterface $fallbackPool): CacheItemPoolInterface
7573
{
7674
if (!$fallbackPool instanceof AdapterInterface) {
7775
$fallbackPool = new ProxyAdapter($fallbackPool);

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ public static function isSupported()
6161
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));
6262
}
6363

64-
/**
65-
* @return bool
66-
*/
67-
public function prune()
64+
public function prune(): bool
6865
{
6966
$time = time();
7067
$pruned = true;
@@ -95,7 +92,7 @@ public function prune()
9592
/**
9693
* {@inheritdoc}
9794
*/
98-
protected function doFetch(array $ids)
95+
protected function doFetch(array $ids): iterable
9996
{
10097
if ($this->appendOnly) {
10198
$now = 0;
@@ -171,7 +168,7 @@ protected function doFetch(array $ids)
171168
/**
172169
* {@inheritdoc}
173170
*/
174-
protected function doHave(string $id)
171+
protected function doHave(string $id): bool
175172
{
176173
if ($this->appendOnly && isset($this->values[$id])) {
177174
return true;
@@ -211,7 +208,7 @@ protected function doHave(string $id)
211208
/**
212209
* {@inheritdoc}
213210
*/
214-
protected function doSave(array $values, int $lifetime)
211+
protected function doSave(array $values, int $lifetime): array|bool
215212
{
216213
$ok = true;
217214
$expiry = $lifetime ? time() + $lifetime : 'PHP_INT_MAX';
@@ -273,7 +270,7 @@ protected function doSave(array $values, int $lifetime)
273270
/**
274271
* {@inheritdoc}
275272
*/
276-
protected function doClear(string $namespace)
273+
protected function doClear(string $namespace): bool
277274
{
278275
$this->values = [];
279276

@@ -283,7 +280,7 @@ protected function doClear(string $namespace)
283280
/**
284281
* {@inheritdoc}
285282
*/
286-
protected function doDelete(array $ids)
283+
protected function doDelete(array $ids): bool
287284
{
288285
foreach ($ids as $id) {
289286
unset($this->values[$id]);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(CacheInterface $pool, string $namespace = '', int $d
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
protected function doFetch(array $ids)
46+
protected function doFetch(array $ids): iterable
4747
{
4848
foreach ($this->pool->getMultiple($ids, $this->miss) as $key => $value) {
4949
if ($this->miss !== $value) {
@@ -55,31 +55,31 @@ protected function doFetch(array $ids)
5555
/**
5656
* {@inheritdoc}
5757
*/
58-
protected function doHave(string $id)
58+
protected function doHave(string $id): bool
5959
{
6060
return $this->pool->has($id);
6161
}
6262

6363
/**
6464
* {@inheritdoc}
6565
*/
66-
protected function doClear(string $namespace)
66+
protected function doClear(string $namespace): bool
6767
{
6868
return $this->pool->clear();
6969
}
7070

7171
/**
7272
* {@inheritdoc}
7373
*/
74-
protected function doDelete(array $ids)
74+
protected function doDelete(array $ids): bool
7575
{
7676
return $this->pool->deleteMultiple($ids);
7777
}
7878

7979
/**
8080
* {@inheritdoc}
8181
*/
82-
protected function doSave(array $values, int $lifetime)
82+
protected function doSave(array $values, int $lifetime): array|bool
8383
{
8484
return $this->pool->setMultiple($values, 0 === $lifetime ? null : $lifetime);
8585
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,7 @@ public function commit(): bool
297297
return $this->invalidateTags([]);
298298
}
299299

300-
/**
301-
* @return array
302-
*/
303-
public function __sleep()
300+
public function __sleep(): array
304301
{
305302
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);
306303
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function commit(): bool
212212
/**
213213
* {@inheritdoc}
214214
*/
215-
public function prune()
215+
public function prune(): bool
216216
{
217217
if (!$this->pool instanceof PruneableInterface) {
218218
return false;

0 commit comments

Comments
 (0)