Skip to content

Fix newly reported PHPStan errors#100

Merged
swissspidy merged 1 commit intomainfrom
fix-phpstan
Feb 13, 2026
Merged

Fix newly reported PHPStan errors#100
swissspidy merged 1 commit intomainfrom
fix-phpstan

Conversation

@swissspidy
Copy link
Member

No description provided.

@swissspidy swissspidy added this to the 2.0.16 milestone Feb 13, 2026
@swissspidy swissspidy requested a review from a team as a code owner February 13, 2026 09:23
Copilot AI review requested due to automatic review settings February 13, 2026 09:23
@gemini-code-assist
Copy link

Summary of Changes

Hello @swissspidy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on addressing newly reported PHPStan errors by modernizing the codebase. It updates array initializations to use the contemporary short array syntax and refines PHPDoc type hints for improved accuracy in static analysis. These changes enhance code consistency and help prevent potential issues identified by static analysis tools.

Highlights

  • Code Modernization: Replaced all instances of the old array() syntax with the modern short array syntax [] for array initializations, improving code readability and consistency.
  • Static Analysis Improvements: Updated PHPDoc type hints for the $author_data variable and parameter to be more precise, specifically array<object{user_email: string, user_login: string}> and array<\WP_User|object{user_email: string, user_login: string}>, which helps PHPStan with better static analysis.
Changelog
  • src/Import_Command.php
    • Replaced array() with [] for array initializations in various properties and local variables.
    • Updated PHPDoc type hints for $author_data to include object{user_email: string, user_login: string} for better type accuracy.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modernizes array syntax and improves PHPDoc types to address PHPStan errors. The changes are generally good, but I've found a few areas for improvement. The new type hints for $author_data are not entirely accurate as they don't reflect that the user_email property is optional. I've left specific suggestions to correct this. Additionally, I found a redundant PHPDoc block that should be removed to improve code clarity. Overall, good work on improving the codebase's quality.


$author_data = array();
/**
* @var array<object{user_email: string, user_login: string}> $author_data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PHPDoc type for $author_data is not entirely correct. The property user_email is optional, as it's only set if isset( $wxr_author['author_email'] ) in the loop below. The current type object{user_email: string, user_login: string} suggests user_email is always present, which can mislead static analysis tools and developers. Please mark it as optional.

 * @var array<object{user_login: string, user_email?: string}> $author_data

Comment on lines 157 to 159
/**
* @var array<\WP_User> $author_data
* @var array<object{user_email: string, user_login: string}> $author_data
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This PHPDoc block for $author_data is redundant, as the variable is already documented at lines 131-133. Duplicate documentation can lead to inconsistencies and should be avoided. Please remove this block.

*
* @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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 can cause issues with static analysis. Please mark user_email as optional.

 * @param array<\WP_User|object{user_login: string, user_email?: string}> $author_data An array of WP_User-esque author objects

* 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Import_Command.php 54.54% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request aims to fix PHPStan errors by updating array syntax from array() to [] and improving PHPDoc type annotations. The changes address static analysis issues detected by PHPStan level 9 configuration.

Changes:

  • Converted several empty array initializations from array() to [] syntax
  • Added and updated PHPDoc type annotations for $author_data variables to use object shape syntax
  • Updated method parameter and return type documentation to reflect actual types used in the code

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

*
* @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
Copy link

Copilot AI Feb 13, 2026

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.

Suggested change
* @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 uses AI. Check for mistakes.
* 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
Copy link

Copilot AI Feb 13, 2026

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.

Suggested change
* @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

Copilot uses AI. Check for mistakes.
Comment on lines 157 to 159
/**
* @var array<\WP_User> $author_data
* @var array<object{user_email: string, user_login: string}> $author_data
*/
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PHPDoc comment on lines 157-159 is redundant and adds no value. The variable $author_data already has the same type annotation on lines 131-133 just 23 lines above, and its type hasn't changed in between. This duplicate comment should be removed.

Copilot uses AI. Check for mistakes.
Comment on lines 416 to 417
$author_mapping[] = array(
'old_user_login' => $author->user_login,
Copy link

Copilot AI Feb 13, 2026

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.

Copilot uses AI. Check for mistakes.
@swissspidy swissspidy merged commit 121ff35 into main Feb 13, 2026
62 of 63 checks passed
@swissspidy swissspidy deleted the fix-phpstan branch February 13, 2026 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants