-
Notifications
You must be signed in to change notification settings - Fork 23
Fix newly reported PHPStan errors #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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<object{user_email: string, user_login: string}> $author_data | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PHPDoc type for * @var array<object{user_login: string, user_email?: string}> $author_data
swissspidy marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| */ | ||||||
| $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<object{user_email: string, user_login: string}> $author_data | ||||||
| */ | ||||||
|
Comment on lines
157
to
159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Comment on lines
157
to
159
|
||||||
|
|
||||||
| // 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 | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type hint for the * @param array<\WP_User|object{user_login: string, user_email?: string}> $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 | |
| * @param array<\WP_User|object{user_login: string, user_email?: string, display_name?: string, first_name?: string, last_name?: string}> $author_data An array of WP_User-esque author objects |
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent array syntax. Lines 416, 450, 460, 467, and 483 in the file all use array( for multi-line array initialization, while line 414 in this same method uses []. For consistency with the pattern established in this PR (converting array() to []), these should also be converted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type hint for the $author_data parameter is incorrect. The user_email property on the object shape is optional, but it's not marked as such. This is evident from the code within this function which checks isset( $author->user_email ). Please mark user_email as optional to reflect this.
* @param array<\WP_User|object{user_login: string, user_email?: string}> $author_data
Copilot
AI
Feb 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type annotation is incomplete and inconsistent with lines 131-133. The objects can have optional properties display_name, first_name, and last_name in addition to user_login and user_email. The type should be array<\WP_User|object{user_login: string, user_email?: string, display_name?: string, first_name?: string, last_name?: string}> to accurately reflect all possible properties.
| * @param array<\WP_User|object{user_email: string, user_login: string}> $author_data | |
| * @param array<\WP_User|object{user_login: string, user_email?: string, display_name?: string, first_name?: string, last_name?: string}> $author_data |
Uh oh!
There was an error while loading. Please reload this page.