Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ parameters:
# `wp icon` and `wp icon collection` abort on WordPress < 7.1 via `before_invoke`.
-
identifier: WPCompat.methodNotAvailable
message: '#^WP_Icon_Collections_Registry::get_instance\(\) is only available since WordPress version 7\.1\.0\.$#'
message: '#^WP_Icon_Collections_Registry::(get_all_registered|get_instance|get_registered|is_registered)\(\) is only available since WordPress version 7\.1\.0\.$#'
paths:
- src/Icon_Collection_Command.php
- src/Icon_Command.php
-
identifier: WPCompat.methodNotAvailable
message: '#^WP_Icons_Registry::get_instance\(\) is only available since WordPress version 7\.0\.0\.$#'
message: '#^WP_Icons_Registry::(get_instance|get_registered_icon|get_registered_icons|is_registered)\(\) is only available since WordPress version 7\.0\.0\.$#'
paths:
- src/Icon_Collection_Command.php
- src/Icon_Command.php
Expand Down Expand Up @@ -129,19 +129,3 @@ parameters:
-
identifier: WPCompat.parameterNotAvailable.wploadalloptions.forcecache
path: src/Option_Command.php

# The Icons API introduced in WordPress 7.0 and 7.1 is not covered by the WordPress
# stubs yet, so PHPStan does not know these symbols at all. `reportUnmatched` keeps
# the entries from turning into errors themselves once the stubs catch up.
-
identifier: class.notFound
message: '#^Call to static method get_instance\(\) on an unknown class WP_(Icons_Registry|Icon_Collections_Registry)\.$#'
reportUnmatched: false
paths:
- src/Icon_Collection_Command.php
- src/Icon_Command.php
-
identifier: function.notFound
message: '#^Function wp_get_icon not found\.$#'
reportUnmatched: false
path: src/Icon_Command.php
4 changes: 2 additions & 2 deletions src/Comment_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,13 @@ public function list_( $args, $assoc_args ) {

if ( 'count' === $formatter->format ) {
/**
* @var int $comments
* @var int<0, max> $comments
*/
echo $comments;
return;
} else {
/**
* @var array $comments
* @var array<int<0, max>|\WP_Comment> $comments
*/

if ( 'ids' === $formatter->format ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ public function list_( $args, $assoc_args ) {
} elseif ( 'count' === $formatter->format ) {
$query_args['fields'] = 'ids';
$query = new WP_Query( $query_args );
$formatter->display_items( $query->posts );
$formatter->display_items( $query->posts ?? [] );
} else {
$query = new WP_Query( $query_args );
$posts = array_map(
Expand All @@ -956,7 +956,7 @@ function ( $post ) {
$post->url = get_permalink( $post->ID );
return $post;
},
$query->posts
$query->posts ?? []
);
$formatter->display_items( $posts );
}
Expand Down
10 changes: 10 additions & 0 deletions src/Site_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,16 @@ function ( $site ) {
* @return \Generator<int, \WP_Site>
*/
private static function get_sites_iterator( $query_args ) {
// 'count' and 'fields' are pinned to the WP_Site_Query defaults, so that
// get_sites() always answers with the WP_Site objects this yields.
$query_args = array_merge(
$query_args,
[
'count' => false,
'fields' => '',
]
);

if ( isset( $query_args['number'] ) ) {
// The arguments are whatever the user passed, so they cannot be narrowed
// to the shape get_sites() documents. WP_Site_Query validates them itself.
Expand Down
17 changes: 6 additions & 11 deletions src/Term_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public function list_( $args, $assoc_args ) {
$assoc_args,
[
'taxonomy' => $args,
'fields' => 'all',
]
)
);
Expand All @@ -158,10 +159,6 @@ public function list_( $args, $assoc_args ) {
if ( is_wp_error( $terms ) ) {
WP_CLI::error( $terms );
}

/**
* @var \WP_Term[] $terms
*/
}

$terms = array_map(
Expand Down Expand Up @@ -603,7 +600,7 @@ public function generate( $args, $assoc_args ) {
WP_CLI::warning( $term );
} else {
$created[] = $term['term_id'];
$previous_term_id = $term['term_id'];
$previous_term_id = absint( $term['term_id'] );
if ( 'ids' === $format ) {
echo $term['term_id'];
if ( $index < $max_id + $count ) {
Expand Down Expand Up @@ -827,9 +824,7 @@ public function migrate( $args, $assoc_args ) {
WP_CLI::error( "Taxonomy term '{$term_reference}' for taxonomy '{$original_taxonomy}' doesn't exist." );
}

$tax = get_taxonomy( $original_taxonomy );

if ( ! $tax ) {
if ( ! taxonomy_exists( $original_taxonomy ) ) {
WP_CLI::error( "Taxonomy '{$original_taxonomy}' doesn't exist." );
}

Expand All @@ -856,7 +851,7 @@ public function migrate( $args, $assoc_args ) {
/**
* @var string[] $post_ids
*/
$post_ids = get_objects_in_term( $term->term_id, $tax->name );
$post_ids = get_objects_in_term( $term->term_id, $original_taxonomy );
$post_count = 0;

foreach ( $post_ids as $post_id ) {
Expand All @@ -881,15 +876,15 @@ public function migrate( $args, $assoc_args ) {

WP_CLI::log( "Term '{$term->slug}' migrated." );

$del = wp_delete_term( $term->term_id, $tax->name );
$del = wp_delete_term( $term->term_id, $original_taxonomy );

if ( is_wp_error( $del ) ) {
WP_CLI::error( "Failed to delete the term '{$term->slug}'. Reason: " . $del->get_error_message() );
}

WP_CLI::log( "Old instance of term '{$term->slug}' removed from its original taxonomy." );
$post_plural = Utils\pluralize( 'post', $post_count );
WP_CLI::success( "Migrated the term '{$term->slug}' from taxonomy '{$tax->name}' to taxonomy '{$destination_taxonomy}' for {$post_count} {$post_plural}." );
WP_CLI::success( "Migrated the term '{$term->slug}' from taxonomy '{$original_taxonomy}' to taxonomy '{$destination_taxonomy}' for {$post_count} {$post_plural}." );
}

private function maybe_make_child() {
Expand Down