4040 * @see https://packagist.org/providers/psr/simple-cache-implementation For existing implementations.
4141 *
4242 * @template T
43- *
44- * @psalm-suppress MoreSpecificImplementedParamType
45- * @psalm-suppress DocblockTypeContradiction
46- * @psalm-suppress RedundantConditionGivenDocblockType
4743 */
4844class Cache implements CacheInterface
4945{
@@ -128,7 +124,7 @@ public function set(string $key, mixed $value, int|DateInterval|null $ttl = null
128124 return true ;
129125 }
130126
131- public function delete ($ key ): bool
127+ public function delete (string $ key ): bool
132128 {
133129 $ this ->assertValidKey ($ key );
134130
@@ -162,17 +158,22 @@ public function getMultiple($keys, $default = null): Generator
162158 }
163159
164160 /**
165- * @param iterable<string , T> $values
161+ * @param iterable<mixed , T> $values
166162 * @param int|DateInterval|null $ttl
167163 *
168164 * @throws InvalidCacheArgumentException
169165 */
170166 public function setMultiple (iterable $ values , null |int |DateInterval $ ttl = null ): bool
171167 {
168+ /**
169+ * @var mixed $key
170+ */
172171 foreach ($ values as $ key => $ value ) {
173172 if (is_int ($ key )) {
174173 $ key = (string ) $ key ;
175174 }
175+ $ this ->assertIsString ($ key );
176+ /** @param string $key */
176177 $ this ->set ($ key , $ value , $ ttl );
177178 }
178179
@@ -198,6 +199,18 @@ private function assertValidKey(string $key): void
198199 }
199200 }
200201
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+
201214 /**
202215 * @template U
203216 *
0 commit comments