Skip to content

Commit 8d70d80

Browse files
[Cache]Add Union Type
1 parent f1372e4 commit 8d70d80

31 files changed

+81
-88
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ interface AdapterInterface extends CacheItemPoolInterface
2929
*
3030
* @return CacheItem
3131
*/
32-
public function getItem($key);
32+
public function getItem(mixed $key);
3333

3434
/**
3535
* {@inheritdoc}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function doFetch(array $ids)
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
protected function doHave(string $id)
80+
protected function doHave(mixed $id)
8181
{
8282
return apcu_exists($id);
8383
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function delete(string $key): bool
100100
*
101101
* @return bool
102102
*/
103-
public function hasItem($key)
103+
public function hasItem(mixed $key)
104104
{
105105
if (\is_string($key) && isset($this->expiries[$key]) && $this->expiries[$key] > microtime(true)) {
106106
if ($this->maxItems) {
@@ -120,7 +120,7 @@ public function hasItem($key)
120120
/**
121121
* {@inheritdoc}
122122
*/
123-
public function getItem($key)
123+
public function getItem(mixed $key)
124124
{
125125
if (!$isHit = $this->hasItem($key)) {
126126
$value = null;
@@ -151,7 +151,7 @@ public function getItems(array $keys = [])
151151
*
152152
* @return bool
153153
*/
154-
public function deleteItem($key)
154+
public function deleteItem(mixed $key)
155155
{
156156
\assert('' !== CacheItem::validateKey($key));
157157
unset($this->values[$key], $this->expiries[$key]);

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

Lines 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)
123+
public function getItem(mixed $key)
124124
{
125125
$syncItem = self::$syncItem;
126126
$misses = [];
@@ -186,7 +186,7 @@ private function generateItems(iterable $items, int $adapterIndex)
186186
*
187187
* @return bool
188188
*/
189-
public function hasItem($key)
189+
public function hasItem(mixed $key)
190190
{
191191
foreach ($this->adapters as $adapter) {
192192
if ($adapter->hasItem($key)) {
@@ -223,7 +223,7 @@ public function clear(string $prefix = '')
223223
*
224224
* @return bool
225225
*/
226-
public function deleteItem($key)
226+
public function deleteItem(mixed $key)
227227
{
228228
$deleted = true;
229229
$i = $this->adapterCount;

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

Lines changed: 3 additions & 6 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];
@@ -182,15 +179,15 @@ protected function doFetch(array $ids)
182179
/**
183180
* {@inheritdoc}
184181
*/
185-
protected function doHave($id): bool
182+
protected function doHave(mixed $id): bool
186183
{
187184
return false !== $this->bucket->get($id);
188185
}
189186

190187
/**
191188
* {@inheritdoc}
192189
*/
193-
protected function doClear($namespace): bool
190+
protected function doClear(string $namespace): bool
194191
{
195192
if ('' === $namespace) {
196193
$this->bucket->manager()->flush();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function doFetch(array $ids)
6565
/**
6666
* {@inheritdoc}
6767
*/
68-
protected function doHave(string $id)
68+
protected function doHave(mixed $id)
6969
{
7070
return $this->provider->contains($id);
7171
}

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

Lines 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];
@@ -285,7 +285,7 @@ protected function doFetch(array $ids)
285285
/**
286286
* {@inheritdoc}
287287
*/
288-
protected function doHave(string $id)
288+
protected function doHave(mixed $id)
289289
{
290290
return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
291291
}

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

Lines changed: 4 additions & 4 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)
53+
public function getItem(mixed $key)
5454
{
5555
return (self::$createCacheItem)($key);
5656
}
@@ -68,7 +68,7 @@ public function getItems(array $keys = [])
6868
*
6969
* @return bool
7070
*/
71-
public function hasItem($key)
71+
public function hasItem(mixed $key)
7272
{
7373
return false;
7474
}
@@ -88,7 +88,7 @@ public function clear(string $prefix = '')
8888
*
8989
* @return bool
9090
*/
91-
public function deleteItem($key)
91+
public function deleteItem(mixed $key)
9292
{
9393
return true;
9494
}
@@ -136,7 +136,7 @@ public function commit()
136136
/**
137137
* {@inheritdoc}
138138
*/
139-
public function delete(string $key): bool
139+
public function delete(mixed $key): bool
140140
{
141141
return $this->deleteItem($key);
142142
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class PdoAdapter extends AbstractAdapter implements PruneableInterface
6666
* @throws InvalidArgumentException When PDO error mode is not PDO::ERRMODE_EXCEPTION
6767
* @throws InvalidArgumentException When namespace contains invalid characters
6868
*/
69-
public function __construct($connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
69+
public function __construct(\PDO | Connection | string $connOrDsn, string $namespace = '', int $defaultLifetime = 0, array $options = [], MarshallerInterface $marshaller = null)
7070
{
7171
if (isset($namespace[0]) && preg_match('#[^-+.A-Za-z0-9]#', $namespace, $match)) {
7272
throw new InvalidArgumentException(sprintf('Namespace contains "%s" but only characters in [-+.A-Za-z0-9] are allowed.', $match[0]));
@@ -259,7 +259,7 @@ protected function doFetch(array $ids)
259259
/**
260260
* {@inheritdoc}
261261
*/
262-
protected function doHave(string $id)
262+
protected function doHave(mixed $id)
263263
{
264264
$sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND ($this->lifetimeCol IS NULL OR $this->lifetimeCol + $this->timeCol > :time)";
265265
$stmt = $this->getConnection()->prepare($sql);

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

Lines 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)
119+
public function getItem(mixed $key)
120120
{
121121
if (!\is_string($key)) {
122122
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
@@ -167,7 +167,7 @@ public function getItems(array $keys = [])
167167
*
168168
* @return bool
169169
*/
170-
public function hasItem($key)
170+
public function hasItem(mixed $key)
171171
{
172172
if (!\is_string($key)) {
173173
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));
@@ -184,7 +184,7 @@ public function hasItem($key)
184184
*
185185
* @return bool
186186
*/
187-
public function deleteItem($key)
187+
public function deleteItem(mixed $key)
188188
{
189189
if (!\is_string($key)) {
190190
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', get_debug_type($key)));

0 commit comments

Comments
 (0)