40
40
* @see https://packagist.org/providers/psr/simple-cache-implementation For existing implementations.
41
41
*
42
42
* @template T
43
- *
44
- * @psalm-suppress MoreSpecificImplementedParamType
45
- * @psalm-suppress DocblockTypeContradiction
46
- * @psalm-suppress RedundantConditionGivenDocblockType
47
43
*/
48
44
class Cache implements CacheInterface
49
45
{
@@ -128,7 +124,7 @@ public function set(string $key, mixed $value, int|DateInterval|null $ttl = null
128
124
return true ;
129
125
}
130
126
131
- public function delete ($ key ): bool
127
+ public function delete (string $ key ): bool
132
128
{
133
129
$ this ->assertValidKey ($ key );
134
130
@@ -162,17 +158,22 @@ public function getMultiple($keys, $default = null): Generator
162
158
}
163
159
164
160
/**
165
- * @param iterable<string , T> $values
161
+ * @param iterable<mixed , T> $values
166
162
* @param int|DateInterval|null $ttl
167
163
*
168
164
* @throws InvalidCacheArgumentException
169
165
*/
170
166
public function setMultiple (iterable $ values , null |int |DateInterval $ ttl = null ): bool
171
167
{
168
+ /**
169
+ * @var mixed $key
170
+ */
172
171
foreach ($ values as $ key => $ value ) {
173
172
if (is_int ($ key )) {
174
173
$ key = (string ) $ key ;
175
174
}
175
+ $ this ->assertIsString ($ key );
176
+ /** @param string $key */
176
177
$ this ->set ($ key , $ value , $ ttl );
177
178
}
178
179
@@ -198,6 +199,18 @@ private function assertValidKey(string $key): void
198
199
}
199
200
}
200
201
202
+ /**
203
+ * @psalm-assert string $key
204
+ *
205
+ * @throws InvalidCacheArgumentException
206
+ */
207
+ private function assertIsString (mixed $ key ): void
208
+ {
209
+ if (!is_string ($ key )) {
210
+ throw new InvalidCacheArgumentException ();
211
+ }
212
+ }
213
+
201
214
/**
202
215
* @template U
203
216
*
0 commit comments