Skip to content

Fix newly reported PHPStan errors#308

Merged
swissspidy merged 2 commits intomainfrom
fix-phpstan
Feb 13, 2026
Merged

Fix newly reported PHPStan errors#308
swissspidy merged 2 commits intomainfrom
fix-phpstan

Conversation

@swissspidy
Copy link
Member

No description provided.

@swissspidy swissspidy requested a review from a team as a code owner February 12, 2026 13:15
Copilot AI review requested due to automatic review settings February 12, 2026 13:15
@swissspidy swissspidy added the scope:testing Related to testing label Feb 12, 2026
@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 primarily addresses and resolves newly reported PHPStan static analysis errors across the codebase. It involves updating a core dependency, introducing precise type definitions for global variables and HTTP responses, and refining PHPDoc comments to ensure better type inference and reduce false positives from the static analyzer. The changes aim to improve code quality and maintainability by making the code more amenable to static analysis.

Highlights

  • Dependency Update: The wp-cli/wp-cli dependency has been updated to version ^2.13 in composer.json.
  • PHPStan Type Definitions: New @phpstan-type definitions and @var PHPDoc comments were introduced in src/Core_Command.php to enhance static analysis accuracy for global variables and HTTP responses.
  • PHPDoc Refinements: Existing PHPDoc comments were refined and @phpstan-param annotations were added in src/Core_Command.php to provide more precise type information for method parameters and return types, aiding PHPStan.
  • Static Analysis Adjustments: PHPDoc comments were adjusted and a @phpstan-ignore directive was added in src/WP_CLI/Core/CoreUpgrader.php to resolve specific static analysis warnings.
Changelog
  • composer.json
    • Updated wp-cli/wp-cli dependency from ^2.12 to ^2.13.
  • src/Core_Command.php
    • Defined HTTP_Response as a @phpstan-type for consistent type hinting.
    • Added @var \wpdb $wpdb PHPDoc for the global $wpdb variable within the do_install method.
    • Replaced direct $GLOBALS['wpdb']->last_error access with $wpdb->last_error after the global declaration.
    • Added @var array{wp_version: string} $GLOBALS PHPDoc to specify the structure of the global $GLOBALS array.
    • Updated @param and added @phpstan-param annotations for set_version_check_error, capture_version_check_error, and capture_version_check_error_from_response methods to provide more accurate type information for static analysis.
  • src/WP_CLI/Core/CoreUpgrader.php
    • Removed a redundant @var PHPDoc and added @phpstan-ignore return.type to suppress a specific PHPStan warning.
    • Added @var array{wpcli_core_update_obj: object{locale: string}} $GLOBALS PHPDoc to clarify the type of a global variable.
Activity
  • No human activity has occurred 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 github-actions bot added the help-wanted Extra attention is needed label Feb 12, 2026
@github-actions
Copy link
Contributor

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 addresses several PHPStan errors by adding more specific type annotations. The changes introduce a phpstan-type for HTTP responses and add @var and @phpstan-param docblocks to clarify variable types for the static analyzer, along with some related code cleanup. These are great improvements for code quality and maintainability. I have one suggestion for improving consistency in how global variables are accessed.

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 PR addresses newly reported PHPStan findings in the WP-CLI core-command package by refining type information and suppressing/clarifying a few hard-to-type WordPress globals and hook return values, and it bumps the required wp-cli/wp-cli version.

Changes:

  • Adjusted PHPStan-related typing around core download caching and $GLOBALS usage in CoreUpgrader.
  • Added PHPStan type aliasing / param annotations and improved typing for $wpdb / $GLOBALS['wp_version'] in Core_Command.
  • Updated composer.json to require wp-cli/wp-cli ^2.13.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/WP_CLI/Core/CoreUpgrader.php PHPStan-related adjustments around filter return typing and $GLOBALS typing for core update locale.
src/Core_Command.php Adds PHPStan type alias/annotations for HTTP responses and globals used during version checks/installs.
composer.json Bumps required wp-cli/wp-cli version to ^2.13.

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

*
* @package wp-cli
*
* @phpstan-type HTTP_Response array{headers: array<string, string>, body: string, response: array{code:false|int, message: false|string}, cookies: array<string, string>, http_response: mixed}
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

The HTTP_Response alias appears to be more specific than WordPress actually guarantees (e.g., cookies are typically WP_Http_Cookie[], and header values aren’t always just string). Consider loosening this alias to only the fields you read in this file (e.g., array{response: array{code:int, message:string}} & array<string, mixed>) or using array<string, mixed> to avoid encoding an incorrect contract into PHPStan types.

Suggested change
* @phpstan-type HTTP_Response array{headers: array<string, string>, body: string, response: array{code:false|int, message: false|string}, cookies: array<string, string>, http_response: mixed}
* @phpstan-type HTTP_Response array{response: array{code:false|int, message:false|string}} & array<string, mixed>

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy swissspidy added this to the 2.1.24 milestone Feb 13, 2026
@swissspidy swissspidy removed the help-wanted Extra attention is needed label Feb 13, 2026
@swissspidy swissspidy merged commit c8fd1ed into main Feb 13, 2026
53 checks passed
@swissspidy swissspidy deleted the fix-phpstan branch February 13, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments