@@ -116,14 +116,16 @@ public function get( $args, $assoc_args ) {
116116 *
117117 * $ wp transient set sample_key "test data" 3600
118118 * Success: Transient added.
119+ *
120+ * @param string[] $args
119121 */
120122 public function set ( $ args , $ assoc_args ) {
121123 list ( $ key , $ value ) = $ args ;
122124
123- $ expiration = Utils \get_flag_value ( $ args, 2 , 0 ) ;
125+ $ expiration = $ args[ 2 ] ?? 0 ;
124126
125127 $ func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'set_site_transient ' : 'set_transient ' ;
126- if ( $ func ( $ key , $ value , $ expiration ) ) {
128+ if ( $ func ( $ key , $ value , ( int ) $ expiration ) ) {
127129 WP_CLI ::success ( 'Transient added. ' );
128130 } else {
129131 WP_CLI ::error ( 'Transient could not be set. ' );
@@ -180,9 +182,9 @@ public function set( $args, $assoc_args ) {
180182 public function delete ( $ args , $ assoc_args ) {
181183 $ key = ( ! empty ( $ args ) ) ? $ args [0 ] : null ;
182184
183- $ all = Utils \get_flag_value ( $ assoc_args , 'all ' );
184- $ expired = Utils \get_flag_value ( $ assoc_args , 'expired ' );
185- $ network = Utils \get_flag_value ( $ assoc_args , 'network ' );
185+ $ all = ( bool ) Utils \get_flag_value ( $ assoc_args , 'all ' );
186+ $ expired = ( bool ) Utils \get_flag_value ( $ assoc_args , 'expired ' );
187+ $ network = ( bool ) Utils \get_flag_value ( $ assoc_args , 'network ' );
186188
187189 if ( true === $ all ) {
188190 $ this ->delete_all ( $ network );
@@ -301,9 +303,9 @@ public function list_( $args, $assoc_args ) {
301303 WP_CLI ::warning ( 'Transients are stored in an external object cache, and this command only shows those stored in the database. ' );
302304 }
303305
304- $ network = Utils \get_flag_value ( $ assoc_args , 'network ' , false );
305- $ unserialize = Utils \get_flag_value ( $ assoc_args , 'unserialize ' , false );
306- $ human_readable = Utils \get_flag_value ( $ assoc_args , 'human-readable ' , false );
306+ $ network = ( bool ) Utils \get_flag_value ( $ assoc_args , 'network ' , false );
307+ $ unserialize = ( bool ) Utils \get_flag_value ( $ assoc_args , 'unserialize ' , false );
308+ $ human_readable = ( bool ) Utils \get_flag_value ( $ assoc_args , 'human-readable ' , false );
307309
308310 $ fields = array ( 'name ' , 'value ' , 'expiration ' );
309311 if ( isset ( $ assoc_args ['fields ' ] ) ) {
@@ -505,7 +507,12 @@ function ( $key ) {
505507 */
506508 public function patch ( $ args , $ assoc_args ) {
507509 list ( $ action , $ key ) = $ args ;
508- $ expiration = (int ) Utils \get_flag_value ( $ assoc_args , 'expiration ' , 0 );
510+
511+ /**
512+ * @var string $expiration
513+ */
514+ $ expiration = Utils \get_flag_value ( $ assoc_args , 'expiration ' , 0 );
515+ $ expiration = (int ) $ expiration ;
509516
510517 $ read_func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'get_site_transient ' : 'get_transient ' ;
511518 $ write_func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'set_site_transient ' : 'set_transient ' ;
@@ -582,20 +589,31 @@ function ( $key ) {
582589 private function get_transient_expiration ( $ name , $ is_site_transient = false , $ human_readable = false ) {
583590 if ( $ is_site_transient ) {
584591 if ( is_multisite () ) {
585- $ expiration = (int ) get_site_option ( '_site_transient_timeout_ ' . $ name );
592+ /**
593+ * @var string $expiration
594+ */
595+ $ expiration = get_site_option ( '_site_transient_timeout_ ' . $ name );
586596 } else {
587- $ expiration = (int ) get_option ( '_site_transient_timeout_ ' . $ name );
597+ /**
598+ * @var string $expiration
599+ */
600+ $ expiration = get_option ( '_site_transient_timeout_ ' . $ name );
588601 }
589602 } else {
590- $ expiration = (int ) get_option ( '_transient_timeout_ ' . $ name );
603+ /**
604+ * @var string $expiration
605+ */
606+ $ expiration = get_option ( '_transient_timeout_ ' . $ name );
591607 }
592608
609+ $ expiration = (int ) $ expiration ;
610+
593611 if ( 0 === $ expiration ) {
594612 return $ human_readable ? 'never expires ' : 'false ' ;
595613 }
596614
597615 if ( ! $ human_readable ) {
598- return $ expiration ;
616+ return ( string ) $ expiration ;
599617 }
600618
601619 $ now = time ();
0 commit comments