Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3275859

Browse filesBrowse files
[Cache] Leverage union types
1 parent 0f1f54d commit 3275859
Copy full SHA for 3275859

20 files changed

+50
-97
lines changed

‎src/Symfony/Component/Cache/Adapter/AdapterInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AdapterInterface.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface AdapterInterface extends CacheItemPoolInterface
2727
/**
2828
* {@inheritdoc}
2929
*/
30-
public function getItem($key): CacheItem;
30+
public function getItem(mixed $key): CacheItem;
3131

3232
/**
3333
* {@inheritdoc}

‎src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ArrayAdapter.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function delete(string $key): bool
9898
/**
9999
* {@inheritdoc}
100100
*/
101-
public function hasItem($key): bool
101+
public function hasItem(mixed $key): bool
102102
{
103103
if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) {
104104
if ($this->maxItems) {
@@ -118,7 +118,7 @@ public function hasItem($key): bool
118118
/**
119119
* {@inheritdoc}
120120
*/
121-
public function getItem($key): CacheItem
121+
public function getItem(mixed $key): CacheItem
122122
{
123123
if (!$isHit = $this->hasItem($key)) {
124124
$value = null;
@@ -147,7 +147,7 @@ public function getItems(array $keys = []): iterable
147147
/**
148148
* {@inheritdoc}
149149
*/
150-
public function deleteItem($key): bool
150+
public function deleteItem(mixed $key): bool
151151
{
152152
\assert('' !== CacheItem::validateKey($key));
153153
unset($this->values[$key], $this->expiries[$key]);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ChainAdapter.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
120120
/**
121121
* {@inheritdoc}
122122
*/
123-
public function getItem($key): CacheItem
123+
public function getItem(mixed $key): CacheItem
124124
{
125125
$syncItem = self::$syncItem;
126126
$misses = [];
@@ -184,7 +184,7 @@ private function generateItems(iterable $items, int $adapterIndex): \Generator
184184
/**
185185
* {@inheritdoc}
186186
*/
187-
public function hasItem($key): bool
187+
public function hasItem(mixed $key): bool
188188
{
189189
foreach ($this->adapters as $adapter) {
190190
if ($adapter->hasItem($key)) {
@@ -217,7 +217,7 @@ public function clear(string $prefix = ''): bool
217217
/**
218218
* {@inheritdoc}
219219
*/
220-
public function deleteItem($key): bool
220+
public function deleteItem(mixed $key): bool
221221
{
222222
$deleted = true;
223223
$i = $this->adapterCount;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ public function __construct(\CouchbaseBucket $bucket, string $namespace = '', in
5454
$this->marshaller = $marshaller ?? new DefaultMarshaller();
5555
}
5656

57-
/**
58-
* @param array|string $servers
59-
*/
60-
public static function createConnection($servers, array $options = []): \CouchbaseBucket
57+
public static function createConnection(array|string $servers, array $options = []): \CouchbaseBucket
6158
{
6259
if (\is_string($servers)) {
6360
$servers = [$servers];

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/MemcachedAdapter.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static function isSupported()
9696
*
9797
* @throws \ErrorException When invalid options or servers are provided
9898
*/
99-
public static function createConnection($servers, array $options = [])
99+
public static function createConnection(array|string $servers, array $options = [])
100100
{
101101
if (\is_string($servers)) {
102102
$servers = [$servers];
@@ -314,7 +314,7 @@ protected function doClear(string $namespace)
314314
return '' === $namespace && $this->getClient()->flush();
315315
}
316316

317-
private function checkResultCode($result)
317+
private function checkResultCode(mixed $result)
318318
{
319319
$code = $this->client->getResultCode();
320320

‎src/Symfony/Component/Cache/Adapter/NullAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/NullAdapter.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
5050
/**
5151
* {@inheritdoc}
5252
*/
53-
public function getItem($key): CacheItem
53+
public function getItem(mixed $key): CacheItem
5454
{
5555
return (self::$createCacheItem)($key);
5656
}
@@ -66,7 +66,7 @@ public function getItems(array $keys = []): iterable
6666
/**
6767
* {@inheritdoc}
6868
*/
69-
public function hasItem($key): bool
69+
public function hasItem(mixed $key): bool
7070
{
7171
return false;
7272
}
@@ -82,7 +82,7 @@ public function clear(string $prefix = ''): bool
8282
/**
8383
* {@inheritdoc}
8484
*/
85-
public function deleteItem($key): bool
85+
public function deleteItem(mixed $key): bool
8686
{
8787
return true;
8888
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/PdoAdapter.php
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,11 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
6060
* * db_password: The password when lazy-connect [default: '']
6161
* * db_connection_options: An array of driver-specific connection options [default: []]
6262
*
63-
* @param \PDO|Connection|string $connOrDsn a \PDO or Connection instance or DSN string or null
64-
*
6563
* @throws InvalidArgumentException When first argument is not PDO nor Connection nor string
6664
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
6765
* @throws InvalidArgumentException When namespace contains invalid characters
6866
*/
69-
public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
67+
public function __construct(\PDO|Connection|string $connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
7068
{
7169
if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
7270
throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
116116
/**
117117
* {@inheritdoc}
118118
*/
119-
public function getItem($key): CacheItem
119+
public function getItem(mixed $key): CacheItem
120120
{
121121
if (!\is_string($key)) {
122122
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
@@ -165,7 +165,7 @@ public function getItems(array $keys = []): iterable
165165
/**
166166
* {@inheritdoc}
167167
*/
168-
public function hasItem($key): bool
168+
public function hasItem(mixed $key): bool
169169
{
170170
if (!\is_string($key)) {
171171
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
@@ -180,7 +180,7 @@ public function hasItem($key): bool
180180
/**
181181
* {@inheritdoc}
182182
*/
183-
public function deleteItem($key): bool
183+
public function deleteItem(mixed $key): bool
184184
{
185185
if (!\is_string($key)) {
186186
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));

‎src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ProxyAdapter.php
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
120120
/**
121121
* {@inheritdoc}
122122
*/
123-
public function getItem($key): CacheItem
123+
public function getItem(mixed $key): CacheItem
124124
{
125125
$item = $this->pool->getItem($this->getId($key));
126126

@@ -144,7 +144,7 @@ public function getItems(array $keys = []): iterable
144144
/**
145145
* {@inheritdoc}
146146
*/
147-
public function hasItem($key): bool
147+
public function hasItem(mixed $key): bool
148148
{
149149
return $this->pool->hasItem($this->getId($key));
150150
}
@@ -164,7 +164,7 @@ public function clear(string $prefix = ''): bool
164164
/**
165165
* {@inheritdoc}
166166
*/
167-
public function deleteItem($key): bool
167+
public function deleteItem(mixed $key): bool
168168
{
169169
return $this->pool->deleteItem($this->getId($key));
170170
}
@@ -245,7 +245,7 @@ private function generateItems(iterable $items): \Generator
245245
}
246246
}
247247

248-
private function getId($key): string
248+
private function getId(mixed $key): string
249249
{
250250
\assert('' !== CacheItem::validateKey($key));
251251

‎src/Symfony/Component/Cache/Adapter/RedisAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/RedisAdapter.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ class RedisAdapter extends AbstractAdapter
2020
{
2121
use RedisTrait;
2222

23-
/**
24-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
25-
* @param string $namespace The default namespace
26-
* @param int $defaultLifetime The default lifetime
27-
*/
28-
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
23+
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
2924
{
3025
$this->init($redis, $namespace, $defaultLifetime, $marshaller);
3126
}

‎src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ class RedisTagAwareAdapter extends AbstractTagAwareAdapter
5858
*/
5959
private $redisEvictionPolicy;
6060

61-
/**
62-
* @param \Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis The redis client
63-
* @param string $namespace The default namespace
64-
* @param int $defaultLifetime The default lifetime
65-
*/
66-
public function __construct($redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
61+
public function __construct(\Redis|\RedisArray|\RedisCluster|\Predis\ClientInterface|RedisProxy|RedisClusterProxy $redis, string $namespace = '', int $defaultLifetime = 0, MarshallerInterface $marshaller = null)
6762
{
6863
if ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof ClusterInterface && !$redis->getConnection() instanceof PredisCluster) {
6964
throw new InvalidArgumentException(sprintf('Unsupported Predis cluster connection: only "%s" is, "%s" given.', PredisCluster::class, get_debug_type($redis->getConnection())));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function invalidateTags(array $tags)
153153
/**
154154
* {@inheritdoc}
155155
*/
156-
public function hasItem($key): bool
156+
public function hasItem(mixed $key): bool
157157
{
158158
if ($this->deferred) {
159159
$this->commit();
@@ -184,7 +184,7 @@ public function hasItem($key): bool
184184
/**
185185
* {@inheritdoc}
186186
*/
187-
public function getItem($key): CacheItem
187+
public function getItem(mixed $key): CacheItem
188188
{
189189
foreach ($this->getItems([$key]) as $item) {
190190
return $item;
@@ -244,7 +244,7 @@ public function clear(string $prefix = ''): bool
244244
/**
245245
* {@inheritdoc}
246246
*/
247-
public function deleteItem($key): bool
247+
public function deleteItem(mixed $key): bool
248248
{
249249
return $this->deleteItems([$key]);
250250
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/TraceableAdapter.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function get(string $key, callable $callback, float $beta = null, array &
7070
/**
7171
* {@inheritdoc}
7272
*/
73-
public function getItem($key): CacheItem
73+
public function getItem(mixed $key): CacheItem
7474
{
7575
$event = $this->start(__FUNCTION__);
7676
try {
@@ -90,7 +90,7 @@ public function getItem($key): CacheItem
9090
/**
9191
* {@inheritdoc}
9292
*/
93-
public function hasItem($key): bool
93+
public function hasItem(mixed $key): bool
9494
{
9595
$event = $this->start(__FUNCTION__);
9696
try {
@@ -103,7 +103,7 @@ public function hasItem($key): bool
103103
/**
104104
* {@inheritdoc}
105105
*/
106-
public function deleteItem($key): bool
106+
public function deleteItem(mixed $key): bool
107107
{
108108
$event = $this->start(__FUNCTION__);
109109
try {

‎src/Symfony/Component/Cache/CacheItem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/CacheItem.php
+3-9Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,9 @@ public function set($value): static
7474
*
7575
* @return $this
7676
*/
77-
public function expiresAt($expiration): static
77+
public function expiresAt(?\DateTimeInterface $expiration): static
7878
{
79-
if (null === $expiration) {
80-
$this->expiry = null;
81-
} elseif ($expiration instanceof \DateTimeInterface) {
82-
$this->expiry = (float) $expiration->format('U.u');
83-
} else {
84-
throw new InvalidArgumentException(sprintf('Expiration date must implement DateTimeInterface or be null, "%s" given.', get_debug_type($expiration)));
85-
}
79+
$this->expiry = null !== $expiration ? (float) $expiration->format('U.u') : null;
8680

8781
return $this;
8882
}
@@ -92,7 +86,7 @@ public function expiresAt($expiration): static
9286
*
9387
* @return $this
9488
*/
95-
public function expiresAfter($time): static
89+
public function expiresAfter(mixed $time): static
9690
{
9791
if (null === $time) {
9892
$this->expiry = null;

‎src/Symfony/Component/Cache/Messenger/EarlyExpirationMessage.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Messenger/EarlyExpirationMessage.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function findCallback(ReverseContainer $reverseContainer): callable
8888
return $callback;
8989
}
9090

91-
private function __construct(CacheItem $item, string $pool, $callback)
91+
private function __construct(CacheItem $item, string $pool, string|array $callback)
9292
{
9393
$this->item = $item;
9494
$this->pool = $pool;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.