Skip to content

Commit b2c10fc

Browse files
committed
Fix newly reported PHPStan errors
1 parent 028a485 commit b2c10fc

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

‎src/Import_Command.php‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
class Import_Command extends WP_CLI_Command {
44

5-
private $blog_users = array();
5+
private $blog_users = [];
66

7-
public $processed_posts = array();
7+
public $processed_posts = [];
88

99
/**
1010
* Imports content from a given WXR file.
@@ -43,7 +43,7 @@ class Import_Command extends WP_CLI_Command {
4343
public function __invoke( $args, $assoc_args ) {
4444
$defaults = array(
4545
'authors' => null,
46-
'skip' => array(),
46+
'skip' => [],
4747
'rewrite_urls' => null,
4848
);
4949
$assoc_args = wp_parse_args( $assoc_args, $defaults );
@@ -61,7 +61,7 @@ public function __invoke( $args, $assoc_args ) {
6161

6262
WP_CLI::log( 'Starting the import process...' );
6363

64-
$new_args = array();
64+
$new_args = [];
6565
foreach ( $args as $arg ) {
6666
if ( is_dir( $arg ) ) {
6767
$dir = WP_CLI\Utils\trailingslashit( $arg );
@@ -128,7 +128,10 @@ private function import_wxr( $file, $args ) {
128128
// memory.
129129
unset( $import_data );
130130

131-
$author_data = array();
131+
/**
132+
* @var array<object{user_email: string, user_login: string}> $author_data
133+
*/
134+
$author_data = [];
132135
foreach ( $wp_import->authors as $wxr_author ) {
133136
$author = new \stdClass();
134137
// Always in the WXR
@@ -152,7 +155,7 @@ private function import_wxr( $file, $args ) {
152155
}
153156

154157
/**
155-
* @var array<\WP_User> $author_data
158+
* @var array<object{user_email: string, user_login: string}> $author_data
156159
*/
157160

158161
// Build the author mapping
@@ -166,8 +169,8 @@ private function import_wxr( $file, $args ) {
166169
unset( $author_mapping, $author_data );
167170

168171
// $user_select needs to be an array of user IDs
169-
$user_select = array();
170-
$invalid_user_select = array();
172+
$user_select = [];
173+
$invalid_user_select = [];
171174
foreach ( $author_out as $author_login ) {
172175
$user = get_user_by( 'login', $author_login );
173176
if ( $user ) {
@@ -351,7 +354,7 @@ private function is_importer_available() {
351354
* Processes how the authors should be mapped
352355
*
353356
* @param string $authors_arg The `--author` argument originally passed to command
354-
* @param array<\WP_User> $author_data An array of WP_User-esque author objects
357+
* @param array<\WP_User|object{user_email: string, user_login: string}> $author_data An array of WP_User-esque author objects
355358
* @return array<\WP_User>|WP_Error Author mapping array if successful, WP_Error if something bad happened
356359
*/
357360
private function process_author_mapping( $authors_arg, $author_data ) {
@@ -373,7 +376,7 @@ private function process_author_mapping( $authors_arg, $author_data ) {
373376

374377
// Skip any sort of author mapping
375378
case 'skip':
376-
return array();
379+
return [];
377380

378381
default:
379382
return new WP_Error( 'invalid-argument', "'authors' argument is invalid." );
@@ -384,7 +387,7 @@ private function process_author_mapping( $authors_arg, $author_data ) {
384387
* Reads an author mapping file.
385388
*/
386389
private function read_author_mapping_file( $file ) {
387-
$author_mapping = array();
390+
$author_mapping = [];
388391

389392
foreach ( new \WP_CLI\Iterators\CSV( $file ) as $i => $author ) {
390393
/**
@@ -408,7 +411,7 @@ private function read_author_mapping_file( $file ) {
408411
private function create_author_mapping_file( $file, $author_data ) {
409412

410413
if ( touch( $file ) ) {
411-
$author_mapping = array();
414+
$author_mapping = [];
412415
foreach ( $author_data as $author ) {
413416
$author_mapping[] = array(
414417
'old_user_login' => $author->user_login,
@@ -434,11 +437,11 @@ private function create_author_mapping_file( $file, $author_data ) {
434437
/**
435438
* Creates users if they don't exist, and build an author mapping file.
436439
*
437-
* @param array<\WP_User> $author_data
440+
* @param array<\WP_User|object{user_email: string, user_login: string}> $author_data
438441
*/
439442
private function create_authors_for_mapping( $author_data ) {
440443

441-
$author_mapping = array();
444+
$author_mapping = [];
442445
foreach ( $author_data as $author ) {
443446

444447
if ( isset( $author->user_email ) ) {
@@ -497,7 +500,7 @@ private function suggest_user( $author_user_login, $author_user_email = '' ) {
497500
}
498501

499502
$shortest = -1;
500-
$shortestavg = array();
503+
$shortestavg = [];
501504

502505
$threshold = floor( ( strlen( $author_user_login ) / 100 ) * 10 ); // 10 % of the strlen are valid
503506
$closest = '';
@@ -507,7 +510,7 @@ private function suggest_user( $author_user_login, $author_user_email = '' ) {
507510
return $user->user_login;
508511
}
509512

510-
$levs = array();
513+
$levs = [];
511514
$levs[] = levenshtein( $author_user_login, $user->display_name );
512515
$levs[] = levenshtein( $author_user_login, $user->user_login );
513516
$levs[] = levenshtein( $author_user_login, $user->user_email );

0 commit comments

Comments
 (0)