Conversation
|
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:
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:123You can find a list of all available Behat steps in our handbook. |
Summary of ChangesHello, 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 significantly enhances the codebase's robustness by integrating PHPStan at level 9. The primary goal is to improve code quality and prevent potential runtime errors through comprehensive static analysis. This involved adding a dedicated PHPStan configuration and refactoring existing code to adhere to strict type-checking rules, ensuring better maintainability and reliability. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces PHPStan configuration and significantly enhances type hinting across the Sidebar_Command and Widget_Command classes to improve code quality and static analysis. This includes adding detailed PHPDoc for properties, return types, and variables, as well as explicit type casting. The review feedback highlights a critical issue in src/Widget_Command.php where get_option() is called without a default, potentially leading to a fatal error if the option is not found. It suggests using the get_widget_options() helper and the null coalescing operator for safer access to widget options.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR introduces PHPStan configuration targeting level 9 and updates the widget/sidebar command implementations with additional type annotations and a few type casts to satisfy stricter static analysis.
Changes:
- Add
phpstan.neon.distwith PHPStan level 9 configuration and scan paths/stubs. - Add PHPDoc type annotations for
$fieldsarrays and severalWidget_Commandhelper methods/locals. - Add a couple of explicit casts to stabilize inferred types (e.g., widget option index/key handling).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/Widget_Command.php |
Adds PHPStan-oriented typing and a few casts in widget option/sidebar widget handling. |
src/Sidebar_Command.php |
Adds a typed PHPDoc for the $fields property. |
phpstan.neon.dist |
Introduces PHPStan level 9 config, scan paths, and ignore rules for missing param/return types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -666,14 +678,18 @@ private function wp_get_sidebars_widgets() { | |||
| unset( $sidebars_widgets['array_version'] ); | |||
| } | |||
|
|
|||
| /** | |||
| * @var array<string, array<int, string>> $sidebars_widgets | |||
| */ | |||
|
|
|||
| return $sidebars_widgets; | |||
There was a problem hiding this comment.
wp_get_sidebars_widgets() declares it returns array<string, array<int, string>>, but get_option('sidebars_widgets', array()) can still return a non-array value (e.g. option stored as false). To match the declared return type and avoid warnings in callers that iterate it, normalize the value to [] when it isn't an array (similar to Sidebar_Command::get_inactive_sidebar_ids()).
| * @param string $name | ||
| * @return array | ||
| * @return array<string, mixed> | ||
| */ | ||
| private function get_widget_options( $name ) { | ||
| return get_option( 'widget_' . $name, array() ); | ||
| $options = get_option( 'widget_' . $name, array() ); | ||
| /** | ||
| * @var array<string,mixed> $options | ||
| */ | ||
| return $options; |
There was a problem hiding this comment.
get_widget_options() is documented/annotated as array<string, mixed>, but throughout this class it is accessed with both string keys (e.g. _multiwidget) and numeric instance indexes. This docblock will misrepresent the type for PHPStan and can lead to offset-type errors; update it to a key type that matches real usage (e.g. array<int|string, mixed> or a more precise shape), and consider normalizing get_option() to an array in case it returns false.
No description provided.