Code Quality: Add PHPStan type coverage for media and upload functions#12313
Code Quality: Add PHPStan type coverage for media and upload functions#12313adamsilverstein wants to merge 1 commit into
Conversation
Add `@phpstan-return`/`@phpstan-param` annotations describing the array shapes returned and accepted by several upload and attachment helpers, and load the phpstan-phpunit type-specifying extension so PHPUnit assertions narrow types during analysis. Only the extension is included, not its `rules.neon`, so no new strict rules are introduced. Annotated functions: - `_wp_handle_upload()`, `wp_handle_upload()`, `wp_handle_sideload()` - `wp_get_upload_dir()`, `wp_upload_dir()` - `wp_get_attachment_metadata()` - `WP_REST_Request::get_file_params()`/`set_file_params()` These changes are documentation/tooling only with no runtime effect, and let core pass a higher PHPStan rule level. Extracted from the HEIC client-side upload work (PR WordPress#11323, #64915) so the type-coverage improvements can be reviewed and landed independently of the feature.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
Move the `@phpstan-return`/`@phpstan-param` annotations and the phpstan-phpunit extension out of this feature branch and into PR WordPress#12313 so the static-analysis work can be reviewed independently of the HEIC upload feature, per code-review feedback. Also correct the `$posts_clauses` test docblock: each recorded entry is the array of SQL clause fragments from the `posts_clauses` filter, so the type is `array[]`, not `string[]`.
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
What?
Adds
@phpstan-return/@phpstan-paramannotations describing the array shapes returned and accepted by several upload and attachment helpers, and loads thephpstan/phpstan-phpunittype-specifying extension so PHPUnit assertions (e.g.assertIsArray(),assertInstanceOf()) narrow types during analysis. Only the extension is included, not itsrules.neon, so no new strict rules are introduced.Annotated functions:
_wp_handle_upload(),wp_handle_upload(),wp_handle_sideload()wp_get_upload_dir(),wp_upload_dir()wp_get_attachment_metadata()WP_REST_Request::get_file_params()/set_file_params()Why?
These changes are documentation/tooling only, with no runtime effect. They let core pass a higher PHPStan rule level on the affected functions.
This work was extracted from the HEIC client-side upload PR (#11323) per code-review feedback, so the static-analysis improvements can be reviewed and landed independently of the feature. When both this and #11323 land, the affected code passes PHPStan rule level 10.
Notes
composer.lockchange is included (matching the originating PR). A follow-upcomposer update phpstan/phpstan-phpunitmay be wanted to pin the lock; core CI does not currently gate on PHPStan or lock consistency.Testing Instructions
composer installcomposer phpstan(or the project's configured command).