@@ -58,11 +58,14 @@ class Cache_Command extends WP_CLI_Command {
5858 * # Add cache.
5959 * $ wp cache add my_key my_group my_value 300
6060 * Success: Added object 'my_key' in group 'my_value'.
61+ *
62+ * @param array{string, string, string, string} $args Positional arguments.
63+ * @param array<mixed> $assoc_args Associative arguments.
6164 */
6265 public function add ( $ args , $ assoc_args ) {
6366 list ( $ key , $ value , $ group , $ expiration ) = $ args ;
6467
65- if ( ! wp_cache_add ( $ key , $ value , $ group , $ expiration ) ) {
68+ if ( ! wp_cache_add ( $ key , $ value , $ group , ( int ) $ expiration ) ) {
6669 WP_CLI ::error ( "Could not add object ' $ key' in group ' $ group'. Does it already exist? " );
6770 }
6871
@@ -96,10 +99,13 @@ public function add( $args, $assoc_args ) {
9699 * # Decrease cache value.
97100 * $ wp cache decr my_key 2 my_group
98101 * 48
102+ *
103+ * @param array{string, string, string} $args Positional arguments.
104+ * @param array<mixed> $assoc_args Associative arguments.
99105 */
100106 public function decr ( $ args , $ assoc_args ) {
101107 list ( $ key , $ offset , $ group ) = $ args ;
102- $ value = wp_cache_decr ( $ key , $ offset , $ group );
108+ $ value = wp_cache_decr ( $ key , ( int ) $ offset , $ group );
103109
104110 if ( false === $ value ) {
105111 WP_CLI ::error ( 'The value was not decremented. ' );
@@ -129,6 +135,9 @@ public function decr( $args, $assoc_args ) {
129135 * # Delete cache.
130136 * $ wp cache delete my_key my_group
131137 * Success: Object deleted.
138+ *
139+ * @param array{string, string} $args Positional arguments.
140+ * @param array<mixed> $assoc_args Associative arguments.
132141 */
133142 public function delete ( $ args , $ assoc_args ) {
134143 list ( $ key , $ group ) = $ args ;
@@ -157,8 +166,9 @@ public function delete( $args, $assoc_args ) {
157166 * $ wp cache flush
158167 * Success: The cache was flushed.
159168 */
160- public function flush ( $ args , $ assoc_args ) {
161-
169+ public function flush () {
170+ // TODO: Needs fixing in wp-cli/wp-cli
171+ // @phpstan-ignore offsetAccess.nonOffsetAccessible
162172 if ( WP_CLI ::has_config ( 'url ' ) && ! empty ( WP_CLI ::get_config ()['url ' ] ) && is_multisite () ) {
163173 WP_CLI ::warning ( 'Flushing the cache may affect all sites in a multisite installation, depending on the implementation of the object cache. ' );
164174 }
@@ -192,6 +202,9 @@ public function flush( $args, $assoc_args ) {
192202 * # Get cache.
193203 * $ wp cache get my_key my_group
194204 * my_value
205+ *
206+ * @param array{string, string} $args Positional arguments.
207+ * @param array<mixed> $assoc_args Associative arguments.
195208 */
196209 public function get ( $ args , $ assoc_args ) {
197210 list ( $ key , $ group ) = $ args ;
@@ -231,10 +244,13 @@ public function get( $args, $assoc_args ) {
231244 * # Increase cache value.
232245 * $ wp cache incr my_key 2 my_group
233246 * 50
247+ *
248+ * @param array{string, string, string} $args Positional arguments.
249+ * @param array<mixed> $assoc_args Associative arguments.
234250 */
235251 public function incr ( $ args , $ assoc_args ) {
236252 list ( $ key , $ offset , $ group ) = $ args ;
237- $ value = wp_cache_incr ( $ key , $ offset , $ group );
253+ $ value = wp_cache_incr ( $ key , ( int ) $ offset , $ group );
238254
239255 if ( false === $ value ) {
240256 WP_CLI ::error ( 'The value was not incremented. ' );
@@ -273,10 +289,13 @@ public function incr( $args, $assoc_args ) {
273289 * # Replace cache.
274290 * $ wp cache replace my_key new_value my_group
275291 * Success: Replaced object 'my_key' in group 'my_group'.
292+ *
293+ * @param array{string, string, string, string} $args Positional arguments.
294+ * @param array<mixed> $assoc_args Associative arguments.
276295 */
277296 public function replace ( $ args , $ assoc_args ) {
278297 list ( $ key , $ value , $ group , $ expiration ) = $ args ;
279- $ result = wp_cache_replace ( $ key , $ value , $ group , $ expiration );
298+ $ result = wp_cache_replace ( $ key , $ value , $ group , ( int ) $ expiration );
280299
281300 if ( false === $ result ) {
282301 WP_CLI ::error ( "Could not replace object ' $ key' in group ' $ group'. Does it not exist? " );
@@ -315,10 +334,13 @@ public function replace( $args, $assoc_args ) {
315334 * # Set cache.
316335 * $ wp cache set my_key my_value my_group 300
317336 * Success: Set object 'my_key' in group 'my_group'.
337+ *
338+ * @param array{string, string, string, string} $args Positional arguments.
339+ * @param array<mixed> $assoc_args Associative arguments.
318340 */
319341 public function set ( $ args , $ assoc_args ) {
320342 list ( $ key , $ value , $ group , $ expiration ) = $ args ;
321- $ result = wp_cache_set ( $ key , $ value , $ group , $ expiration );
343+ $ result = wp_cache_set ( $ key , $ value , $ group , ( int ) $ expiration );
322344
323345 if ( false === $ result ) {
324346 WP_CLI ::error ( "Could not add object ' $ key' in group ' $ group'. " );
@@ -341,7 +363,7 @@ public function set( $args, $assoc_args ) {
341363 * $ wp cache type
342364 * Default
343365 */
344- public function type ( $ args , $ assoc_args ) {
366+ public function type () {
345367 $ message = WP_CLI \Utils \wp_get_cache_type ();
346368 WP_CLI ::line ( $ message );
347369 }
@@ -365,8 +387,10 @@ public function type( $args, $assoc_args ) {
365387 * if ! wp cache supports non_existing; then
366388 * echo 'non_existing is not supported'
367389 * fi
390+ *
391+ * @param array{string} $args Positional arguments.
368392 */
369- public function supports ( $ args, $ assoc_args ) {
393+ public function supports ( $ args ) {
370394 list ( $ feature ) = $ args ;
371395
372396 if ( ! function_exists ( 'wp_cache_supports ' ) ) {
@@ -396,8 +420,10 @@ public function supports( $args, $assoc_args ) {
396420 * Success: Cache group 'my_group' was flushed.
397421 *
398422 * @subcommand flush-group
423+ *
424+ * @param array{string} $args Positional arguments.
399425 */
400- public function flush_group ( $ args, $ assoc_args ) {
426+ public function flush_group ( $ args ) {
401427 list ( $ group ) = $ args ;
402428
403429 if ( ! function_exists ( 'wp_cache_supports ' ) || ! wp_cache_supports ( 'flush_group ' ) ) {
@@ -436,10 +462,14 @@ public function flush_group( $args, $assoc_args ) {
436462 * - json
437463 * - yaml
438464 * ---
465+ *
466+ * @param array{string, string} $args Positional arguments.
467+ * @param array{group: string, format: string} $assoc_args Associative arguments.
439468 */
440469 public function pluck ( $ args , $ assoc_args ) {
441470 list ( $ key ) = $ args ;
442- $ group = Utils \get_flag_value ( $ assoc_args , 'group ' );
471+
472+ $ group = Utils \get_flag_value ( $ assoc_args , 'group ' );
443473
444474 $ value = wp_cache_get ( $ key , $ group );
445475
@@ -512,11 +542,16 @@ function ( $key ) {
512542 * - plaintext
513543 * - json
514544 * ---
545+ *
546+ * @param string[] $args Positional arguments.
547+ * @param array{group: string, expiration: string, format: string} $assoc_args Associative arguments.
515548 */
516549 public function patch ( $ args , $ assoc_args ) {
517550 list ( $ action , $ key ) = $ args ;
518- $ group = Utils \get_flag_value ( $ assoc_args , 'group ' );
519- $ expiration = Utils \get_flag_value ( $ assoc_args , 'expiration ' );
551+
552+ $ group = Utils \get_flag_value ( $ assoc_args , 'group ' );
553+
554+ $ expiration = Utils \get_flag_value ( $ assoc_args , 'expiration ' );
520555
521556 $ key_path = array_map (
522557 function ( $ key ) {
@@ -569,7 +604,7 @@ function ( $key ) {
569604 if ( $ patched_value === $ old_value ) {
570605 WP_CLI ::success ( "Value passed for cache key ' $ key' is unchanged. " );
571606 } else {
572- $ success = wp_cache_set ( $ key , $ patched_value , $ group , $ expiration );
607+ $ success = wp_cache_set ( $ key , $ patched_value , $ group , ( int ) $ expiration );
573608 if ( $ success ) {
574609 WP_CLI ::success ( "Updated cache key ' $ key'. " );
575610 } else {
0 commit comments