Skip to content

Commit f2f3a25

Browse files
committed
More type fixes
1 parent 7b6bde6 commit f2f3a25

13 files changed

+98
-26
lines changed

src/Comment_Command.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,6 @@ public function get( $args, $assoc_args ) {
367367
public function list_( $args, $assoc_args ) {
368368
$formatter = $this->get_formatter( $assoc_args );
369369

370-
// To be fixed in wp-cli/wp-cli.
371-
// @phpstan-ignore property.notFound
372370
if ( 'ids' === $formatter->format ) {
373371
$assoc_args['fields'] = 'comment_ID';
374372
}

src/Comment_Meta_Command.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_va
7676
* specified.
7777
*
7878
* @return mixed Single metadata value, or array of values.
79+
*
80+
* @phpstan-return ($single is true ? string : $meta_key is "" ? array<array<string>> : array<string>)
7981
*/
8082
protected function get_metadata( $object_id, $meta_key = '', $single = false ) {
83+
// @phpstan-ignore return.type
8184
return get_comment_meta( $object_id, $meta_key, $single );
8285
}
8386

@@ -110,6 +113,6 @@ protected function delete_metadata( $object_id, $meta_key, $meta_value = '' ) {
110113
protected function check_object_id( $object_id ) {
111114
$fetcher = new CommentFetcher();
112115
$comment = $fetcher->get_check( (string) $object_id );
113-
return $comment->comment_ID;
116+
return (int) $comment->comment_ID;
114117
}
115118
}

src/Menu_Item_Command.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,10 @@ public function delete( $args, $assoc_args ) {
367367

368368
foreach ( $args as $arg ) {
369369

370-
$post = get_post( $arg );
371-
$menu_term = get_the_terms( $arg, 'nav_menu' );
370+
$post = get_post( $arg );
371+
$menu_term = get_the_terms( $arg, 'nav_menu' );
372+
373+
// @phpstan-ignore cast.int
372374
$parent_menu_id = (int) get_post_meta( $arg, '_menu_item_menu_item_parent', true );
373375
$result = wp_delete_post( $arg, true );
374376
if ( ! $result ) {

src/Menu_Location_Command.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ public function list_( $args, $assoc_args ) {
7777

7878
$formatter = new Formatter( $assoc_args, [ 'location', 'description' ] );
7979

80-
// To be fixed in wp-cli/wp-cli.
81-
// @phpstan-ignore property.notFound
8280
if ( 'ids' === $formatter->format ) {
8381
$ids = array_map(
8482
function ( $o ) {

src/Option_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function ( $a, $b ) use ( $orderby, $order ) {
329329
: $b->$orderby <=> $a->$orderby;
330330
}
331331
);
332-
} elseif ( 'option_id' === $orderby && 'desc' === $order ) { // Sort by default descending.
332+
} elseif ( 'desc' === $order ) { // Sort by default descending.
333333
krsort( $results );
334334
}
335335

src/Post_Command.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@ public function list_( $args, $assoc_args ) {
636636
$query_args['post_type'] = explode( ',', $query_args['post_type'] );
637637
}
638638

639-
// To be fixed in wp-cli/wp-cli.
640-
// @phpstan-ignore property.notFound
641639
if ( 'ids' === $formatter->format ) {
642640
$query_args['fields'] = 'ids';
643641
$query = new WP_Query( $query_args );
@@ -744,6 +742,9 @@ function ( $post ) {
744742
* Success: Added custom field.
745743
* Success: Added custom field.
746744
* Success: Added custom field.
745+
*
746+
* @param array<string> $args Positional arguments. Unused.
747+
* @param array{count: string, post_type: string, post_status: string, post_title: string, post_author: string, post_date?: string, post_date_gmt?: string, post_content?: string, max_depth: string, format: string} $assoc_args Associative arguments.
747748
*/
748749
public function generate( $args, $assoc_args ) {
749750
global $wpdb;
@@ -800,7 +801,7 @@ public function generate( $args, $assoc_args ) {
800801
WP_CLI::error( 'The parameter `post_content` reads from STDIN.' );
801802
}
802803

803-
$post_data['post_content'] = file_get_contents( 'php://stdin' );
804+
$post_data['post_content'] = (string) file_get_contents( 'php://stdin' );
804805
}
805806

806807
// Get the total number of posts.
@@ -821,7 +822,7 @@ public function generate( $args, $assoc_args ) {
821822

822823
$notify = false;
823824
if ( 'progress' === $format ) {
824-
$notify = Utils\make_progress_bar( 'Generating posts', $post_data['count'] );
825+
$notify = Utils\make_progress_bar( 'Generating posts', (int) $post_data['count'] );
825826
}
826827

827828
$previous_post_id = 0;
@@ -851,7 +852,7 @@ public function generate( $args, $assoc_args ) {
851852
? $label
852853
: "{$label} {$index}",
853854
'post_status' => $post_data['post_status'],
854-
'post_author' => $post_data['post_author'],
855+
'post_author' => (int) $post_data['post_author'],
855856
'post_parent' => $current_parent,
856857
'post_name' => ! empty( $post_data['post_title'] )
857858
? sanitize_title( $post_data['post_title'] . ( $index === $total ? '' : "-{$index}" ) )
@@ -875,10 +876,12 @@ public function generate( $args, $assoc_args ) {
875876
}
876877

877878
if ( 'progress' === $format ) {
879+
// @phpstan-ignore method.nonObject
878880
$notify->tick();
879881
}
880882
}
881883
if ( 'progress' === $format ) {
884+
// @phpstan-ignore method.nonObject
882885
$notify->finish();
883886
}
884887
}

src/Post_Meta_Command.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_va
8888
* specified.
8989
*
9090
* @return mixed Single metadata value, or array of values.
91+
*
92+
* @phpstan-return ($single is true ? string : $meta_key is "" ? array<array<string>> : array<string>)
9193
*/
9294
protected function get_metadata( $object_id, $meta_key = '', $single = false ) {
95+
// @phpstan-ignore return.type
9396
return get_post_meta( $object_id, $meta_key, $single );
9497
}
9598

src/Site_Command.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ private function empty_posts() {
7272
$taxonomies = get_taxonomies();
7373

7474
while ( $posts->valid() ) {
75-
$post_id = $posts->current()->ID;
75+
/**
76+
* @var object{ID: int} $post
77+
*/
78+
$post = $posts->current();
79+
80+
$post_id = $post->ID;
7681

7782
wp_cache_delete( $post_id, 'posts' );
7883
wp_cache_delete( $post_id, 'post_meta' );
@@ -138,7 +143,12 @@ private function empty_links() {
138143
wp_cache_delete( 'get_bookmarks', 'bookmark' );
139144

140145
while ( $links->valid() ) {
141-
$link_id = $links->current()->link_id;
146+
/**
147+
* @var object{link_id: int} $link
148+
*/
149+
$link = $links->current();
150+
151+
$link_id = $link->link_id;
142152

143153
// Remove cache for the link.
144154
wp_delete_object_term_relationships( $link_id, 'link_category' );

src/Site_Meta_Command.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Site_Meta_Command extends CommandWithMeta {
3636
protected function check_object_id( $object_id ) {
3737
$fetcher = new SiteFetcher();
3838
$site = $fetcher->get_check( (string) $object_id );
39+
// TODO: Fix upstream.
40+
// @phpstan-ignore property.notFound
3941
return $site->blog_id;
4042
}
4143

@@ -88,8 +90,11 @@ protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_va
8890
* specified.
8991
*
9092
* @return mixed Single metadata value, or array of values.
93+
*
94+
* @phpstan-return ($single is true ? string : $meta_key is "" ? array<array<string>> : array<string>)
9195
*/
9296
protected function get_metadata( $object_id, $meta_key = '', $single = false ) {
97+
// @phpstan-ignore return.type
9398
return get_site_meta( $object_id, $meta_key, $single );
9499
}
95100

src/Term_Meta_Command.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ protected function check_object_id( $object_id ) {
5454
* will be made.
5555
*
5656
* @return int|false|WP_Error The meta ID on success, false on failure, WP_Error when term_id is ambiguous between taxonomies.
57+
*
58+
* @phpstan-ignore method.childReturnType
5759
*/
5860
protected function add_metadata( $object_id, $meta_key, $meta_value, $unique = false ) {
5961
return add_term_meta( $object_id, $meta_key, $meta_value, $unique );
@@ -72,6 +74,8 @@ protected function add_metadata( $object_id, $meta_key, $meta_value, $unique = f
7274
*
7375
* @return int|bool|WP_Error Meta ID if the key didn't exist, true on successful
7476
* update, false on failure, WP_Error when term_id is ambiguous between taxonomies.
77+
*
78+
* @phpstan-ignore method.childReturnType
7579
*/
7680
protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_value = '' ) {
7781
return update_term_meta( $object_id, $meta_key, $meta_value, $prev_value );
@@ -89,8 +93,11 @@ protected function update_metadata( $object_id, $meta_key, $meta_value, $prev_va
8993
* specified.
9094
*
9195
* @return mixed Single metadata value, or array of values.
96+
*
97+
* @phpstan-return ($single is true ? string : $meta_key is "" ? array<array<string>> : array<string>)
9298
*/
9399
protected function get_metadata( $object_id, $meta_key = '', $single = false ) {
100+
// @phpstan-ignore return.type
94101
return get_term_meta( $object_id, $meta_key, $single );
95102
}
96103

0 commit comments

Comments
 (0)