From b2c10fce333558565cf242bcd018037b6bffde3c Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 13 Feb 2026 10:22:26 +0100 Subject: [PATCH] Fix newly reported PHPStan errors --- src/Import_Command.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Import_Command.php b/src/Import_Command.php index 72cefe0f..4da4740e 100644 --- a/src/Import_Command.php +++ b/src/Import_Command.php @@ -2,9 +2,9 @@ class Import_Command extends WP_CLI_Command { - private $blog_users = array(); + private $blog_users = []; - public $processed_posts = array(); + public $processed_posts = []; /** * Imports content from a given WXR file. @@ -43,7 +43,7 @@ class Import_Command extends WP_CLI_Command { public function __invoke( $args, $assoc_args ) { $defaults = array( 'authors' => null, - 'skip' => array(), + 'skip' => [], 'rewrite_urls' => null, ); $assoc_args = wp_parse_args( $assoc_args, $defaults ); @@ -61,7 +61,7 @@ public function __invoke( $args, $assoc_args ) { WP_CLI::log( 'Starting the import process...' ); - $new_args = array(); + $new_args = []; foreach ( $args as $arg ) { if ( is_dir( $arg ) ) { $dir = WP_CLI\Utils\trailingslashit( $arg ); @@ -128,7 +128,10 @@ private function import_wxr( $file, $args ) { // memory. unset( $import_data ); - $author_data = array(); + /** + * @var array $author_data + */ + $author_data = []; foreach ( $wp_import->authors as $wxr_author ) { $author = new \stdClass(); // Always in the WXR @@ -152,7 +155,7 @@ private function import_wxr( $file, $args ) { } /** - * @var array<\WP_User> $author_data + * @var array $author_data */ // Build the author mapping @@ -166,8 +169,8 @@ private function import_wxr( $file, $args ) { unset( $author_mapping, $author_data ); // $user_select needs to be an array of user IDs - $user_select = array(); - $invalid_user_select = array(); + $user_select = []; + $invalid_user_select = []; foreach ( $author_out as $author_login ) { $user = get_user_by( 'login', $author_login ); if ( $user ) { @@ -351,7 +354,7 @@ private function is_importer_available() { * Processes how the authors should be mapped * * @param string $authors_arg The `--author` argument originally passed to command - * @param array<\WP_User> $author_data An array of WP_User-esque author objects + * @param array<\WP_User|object{user_email: string, user_login: string}> $author_data An array of WP_User-esque author objects * @return array<\WP_User>|WP_Error Author mapping array if successful, WP_Error if something bad happened */ private function process_author_mapping( $authors_arg, $author_data ) { @@ -373,7 +376,7 @@ private function process_author_mapping( $authors_arg, $author_data ) { // Skip any sort of author mapping case 'skip': - return array(); + return []; default: return new WP_Error( 'invalid-argument', "'authors' argument is invalid." ); @@ -384,7 +387,7 @@ private function process_author_mapping( $authors_arg, $author_data ) { * Reads an author mapping file. */ private function read_author_mapping_file( $file ) { - $author_mapping = array(); + $author_mapping = []; foreach ( new \WP_CLI\Iterators\CSV( $file ) as $i => $author ) { /** @@ -408,7 +411,7 @@ private function read_author_mapping_file( $file ) { private function create_author_mapping_file( $file, $author_data ) { if ( touch( $file ) ) { - $author_mapping = array(); + $author_mapping = []; foreach ( $author_data as $author ) { $author_mapping[] = array( 'old_user_login' => $author->user_login, @@ -434,11 +437,11 @@ private function create_author_mapping_file( $file, $author_data ) { /** * Creates users if they don't exist, and build an author mapping file. * - * @param array<\WP_User> $author_data + * @param array<\WP_User|object{user_email: string, user_login: string}> $author_data */ private function create_authors_for_mapping( $author_data ) { - $author_mapping = array(); + $author_mapping = []; foreach ( $author_data as $author ) { if ( isset( $author->user_email ) ) { @@ -497,7 +500,7 @@ private function suggest_user( $author_user_login, $author_user_email = '' ) { } $shortest = -1; - $shortestavg = array(); + $shortestavg = []; $threshold = floor( ( strlen( $author_user_login ) / 100 ) * 10 ); // 10 % of the strlen are valid $closest = ''; @@ -507,7 +510,7 @@ private function suggest_user( $author_user_login, $author_user_email = '' ) { return $user->user_login; } - $levs = array(); + $levs = []; $levs[] = levenshtein( $author_user_login, $user->display_name ); $levs[] = levenshtein( $author_user_login, $user->user_login ); $levs[] = levenshtein( $author_user_login, $user->user_email );