1010use Psr \Log \LoggerAwareTrait ;
1111use Psr \Log \LogLevel ;
1212use Psr \SimpleCache \CacheInterface ;
13+ use Psr \SimpleCache \InvalidArgumentException ;
1314use Throwable ;
1415use Traversable ;
1516use Yiisoft \Db \Command \Param ;
@@ -73,7 +74,7 @@ public function get(string $key, mixed $default = null): mixed
7374 {
7475 $ this ->validateKey ($ key );
7576
76- /** @var bool|float|int|string|null */
77+ /** @var bool|float|int|string|null $value */
7778 $ value = $ this ->getData ($ key , ['data ' ], 'scalar ' );
7879
7980 return $ value === false ? $ default : unserialize ((string ) $ value );
@@ -83,6 +84,8 @@ public function get(string $key, mixed $default = null): mixed
8384 * @param string $key The cache data ID.
8485 * @param mixed $value The cache data value.
8586 * @param DateInterval|int|string|null $ttl The cache data TTL.
87+ *
88+ * @throws InvalidArgumentException
8689 */
8790 public function set (string $ key , mixed $ value , DateInterval |int |string |null $ ttl = null ): bool
8891 {
@@ -126,7 +129,7 @@ public function clear(): bool
126129
127130 public function getMultiple (iterable $ keys , mixed $ default = null ): iterable
128131 {
129- /** @psalm-var array<array-key,array-key> */
132+ /** @psalm-var array<array-key,array-key> $keys */
130133 $ keys = $ this ->iterableToArray ($ keys );
131134 $ this ->validateKeys ($ keys );
132135 $ values = array_fill_keys ($ keys , $ default );
@@ -137,7 +140,7 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable
137140 $ value ['data ' ] = stream_get_contents ($ value ['data ' ]);
138141 }
139142
140- /** @var string */
143+ /** @psalm- var string */
141144 $ values [$ value ['id ' ]] = unserialize ((string ) $ value ['data ' ]);
142145 }
143146
@@ -148,14 +151,16 @@ public function getMultiple(iterable $keys, mixed $default = null): iterable
148151 /**
149152 * @param iterable $values A list of key => value pairs for a multiple-set operation.
150153 * @param DateInterval|int|string|null $ttl The cache data TTL.
154+ *
155+ * @throws InvalidArgumentException
151156 */
152157 public function setMultiple (iterable $ values , DateInterval |int |string |null $ ttl = null ): bool
153158 {
154159 $ ttl = $ this ->normalizeTtl ($ ttl );
155160 $ values = $ this ->iterableToArray ($ values );
156161 $ rows = $ keys = [];
157162
158- /** @var mixed $value */
163+ /** @psalm- var mixed $value */
159164 foreach ($ values as $ key => $ value ) {
160165 $ key = (string ) $ key ;
161166 $ this ->validateKey ($ key );
@@ -224,7 +229,7 @@ public function setLoggerMessageUpdate(string $value): void
224229 *
225230 * @param array|string $id One or more IDs for deleting data.
226231 * @param array $fields Selectable fields.
227- * @param string $method Method of the returned data ( "all", "scalar", "exists").
232+ * @param string $method Method of the returned data ("all", "scalar", "exists").
228233 *
229234 * @return mixed The cache data.
230235 */
@@ -243,7 +248,7 @@ private function getData(array|string $id, array $fields, string $method): mixed
243248 }
244249
245250 /**
246- * Deletes a cache data from the database.
251+ * Deletes cache data from the database.
247252 *
248253 * @param array|bool|string $id One or more IDs for deleting data.
249254 *
@@ -336,24 +341,30 @@ private function isInfinityTtl(?int $ttl): bool
336341 }
337342
338343 /**
339- * Converts iterable to array. If provided value is not iterable it throws an InvalidArgumentException.
344+ * Converts iterable to array. If provided value isn't iterable, it throws an InvalidArgumentException.
340345 */
341346 private function iterableToArray (iterable $ iterable ): array
342347 {
343348 /** @psalm-suppress RedundantCast */
344349 return $ iterable instanceof Traversable ? iterator_to_array ($ iterable ) : (array ) $ iterable ;
345350 }
346351
352+ /**
353+ * @throws InvalidArgumentException
354+ */
347355 private function validateKey (mixed $ key ): void
348356 {
349357 if (!is_string ($ key ) || $ key === '' || strpbrk ($ key , '{}()/\@: ' )) {
350- throw new InvalidArgumentException ('Invalid key value. ' );
358+ throw new \ Yiisoft \ Cache \ Db \ InvalidArgumentException ('Invalid key value. ' );
351359 }
352360 }
353361
362+ /**
363+ * @throws InvalidArgumentException
364+ */
354365 private function validateKeys (array $ keys ): void
355366 {
356- /** @var mixed $key */
367+ /** @psalm- var mixed $key */
357368 foreach ($ keys as $ key ) {
358369 $ this ->validateKey ($ key );
359370 }
0 commit comments