@@ -243,6 +243,7 @@ public function get( $args, $assoc_args ) {
243243 }
244244
245245 if ( ! isset ( $ comment ->url ) ) {
246+ // @phpstan-ignore property.notFound
246247 $ comment ->url = get_comment_link ( $ comment );
247248 }
248249
@@ -376,29 +377,27 @@ public function list_( $args, $assoc_args ) {
376377 $ assoc_args ['count ' ] = true ;
377378 }
378379
379- if ( ! empty ( $ assoc_args ['comment__in ' ] )
380- && ! empty ( $ assoc_args ['orderby ' ] )
381- && 'comment__in ' === $ assoc_args ['orderby ' ]
382- && Utils \wp_version_compare ( '4.4 ' , '< ' ) ) {
383- $ comments = [];
384- foreach ( $ assoc_args ['comment__in ' ] as $ comment_id ) {
385- $ comment = get_comment ( $ comment_id );
386- if ( $ comment ) {
387- $ comments [] = $ comment ;
388- } else {
389- WP_CLI ::warning ( "Invalid comment {$ comment_id }. " );
390- }
391- }
392- } else {
393- $ query = new WP_Comment_Query ();
394- $ comments = $ query ->query ( $ assoc_args );
395- }
380+ $ query = new WP_Comment_Query ();
381+ $ comments = $ query ->query ( $ assoc_args );
396382
397383 if ( 'count ' === $ formatter ->format ) {
384+ /**
385+ * @var int $comments
386+ */
398387 echo $ comments ;
388+ return ;
399389 } else {
390+ /**
391+ * @var array $comments
392+ */
393+
400394 if ( 'ids ' === $ formatter ->format ) {
401- $ comments = wp_list_pluck ( $ comments , 'comment_ID ' );
395+ /**
396+ * @var \WP_Comment[] $comments
397+ */
398+ $ items = wp_list_pluck ( $ comments , 'comment_ID ' );
399+
400+ $ comments = $ items ;
402401 } elseif ( is_array ( $ comments ) ) {
403402 $ comments = array_map (
404403 function ( $ comment ) {
@@ -439,7 +438,7 @@ public function delete( $args, $assoc_args ) {
439438 $ args ,
440439 $ assoc_args ,
441440 function ( $ comment_id , $ assoc_args ) {
442- $ force = Utils \get_flag_value ( $ assoc_args , 'force ' );
441+ $ force = ( bool ) Utils \get_flag_value ( $ assoc_args , 'force ' );
443442
444443 $ status = wp_get_comment_status ( $ comment_id );
445444 $ result = wp_delete_comment ( $ comment_id , $ force );
@@ -457,6 +456,9 @@ function ( $comment_id, $assoc_args ) {
457456 private function call ( $ args , $ status , $ success , $ failure ) {
458457 $ comment_id = absint ( $ args );
459458
459+ /**
460+ * @var callable $func
461+ */
460462 $ func = "wp_ {$ status }_comment " ;
461463
462464 if ( ! $ func ( $ comment_id ) ) {
@@ -642,16 +644,17 @@ public function unapprove( $args, $assoc_args ) {
642644 * total_comments: 19
643645 */
644646 public function count ( $ args , $ assoc_args ) {
645- $ post_id = Utils \get_flag_value ( $ args, 0 , 0 ) ;
647+ $ post_id = $ args[ 0 ] ?? null ;
646648
647649 $ count = wp_count_comments ( $ post_id );
648650
649651 // Move total_comments to the end of the object
650652 $ total = $ count ->total_comments ;
651653 unset( $ count ->total_comments );
654+ // @phpstan-ignore assign.propertyReadOnly
652655 $ count ->total_comments = $ total ;
653656
654- foreach ( $ count as $ status => $ count ) {
657+ foreach ( ( array ) $ count as $ status => $ count ) {
655658 WP_CLI ::line ( str_pad ( "$ status: " , 17 ) . $ count );
656659 }
657660 }
@@ -673,6 +676,9 @@ public function count( $args, $assoc_args ) {
673676 public function recount ( $ args ) {
674677 foreach ( $ args as $ id ) {
675678 if ( wp_update_comment_count ( $ id ) ) {
679+ /**
680+ * @var \WP_Post $post
681+ */
676682 $ post = get_post ( $ id );
677683 WP_CLI ::log ( "Updated post {$ post ->ID } comment count to {$ post ->comment_count }. " );
678684 } else {
0 commit comments