Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Code Quality: Add PHPStan type coverage for media and upload functions#12313

Open
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:add/phpstan-media-upload-types
Open

Code Quality: Add PHPStan type coverage for media and upload functions#12313
adamsilverstein wants to merge 1 commit into
WordPress:trunkfrom
adamsilverstein:add/phpstan-media-upload-types

Conversation

@adamsilverstein

Copy link
Copy Markdown
Member

What?

Adds @phpstan-return/@phpstan-param annotations describing the array shapes returned and accepted by several upload and attachment helpers, and loads the phpstan/phpstan-phpunit type-specifying extension so PHPUnit assertions (e.g. assertIsArray(), assertInstanceOf()) 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()

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

  • No composer.lock change is included (matching the originating PR). A follow-up composer update phpstan/phpstan-phpunit may be wanted to pin the lock; core CI does not currently gate on PHPStan or lock consistency.
  • May warrant its own Trac ticket for the code-quality milestone; currently associated with the HEIC work under #64915.

Testing Instructions

  1. composer install
  2. Run PHPStan: composer phpstan (or the project's configured command).
  3. Confirm no new errors are reported and the annotated functions analyze at the higher level.

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.
@github-actions

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props adamsilverstein.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Hi there! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

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,
The WordPress Project

adamsilverstein added a commit to adamsilverstein/wordpress-develop that referenced this pull request Jun 25, 2026
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[]`.
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yessssss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants