Enhance WP_REST_Posts_Controller with writable PreparedPost and static analysis fixes#11336
Draft
westonruter wants to merge 16 commits intoWordPress:trunkfrom
Draft
Enhance WP_REST_Posts_Controller with writable PreparedPost and static analysis fixes#11336westonruter wants to merge 16 commits intoWordPress:trunkfrom
WP_REST_Posts_Controller with writable PreparedPost and static analysis fixes#11336westonruter wants to merge 16 commits intoWordPress:trunkfrom
Conversation
…tem_for_database()
PHPStan treats object{} shape properties as read-only by default.
Since prepare_item_for_database() returns a stdClass that callers
mutate (e.g. setting post_type, post_name), the PreparedPost type
needs to be intersected with stdClass to indicate properties are
writable.
See: phpstan/phpstan#10079
See: https://phpstan.org/writing-php-code/phpdoc-types
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This primarily is for fixing calls to
wp_unique_post_slug()in\WP_REST_Posts_Controller::create_item()and\WP_REST_Posts_Controller::update_item(). However, as part of that I also looked atWP_REST_Posts_Controller::prepare_item_for_database()and all methods that called it to ensure that they also had their static analysis issues addressed. I don't intend to commit this entire PR as-is. Subsets would be committed at a time, ideally with tests to catch the holes identified by static analysisTrac ticket: https://core.trac.wordpress.org/ticket/64921
Use of AI Tools
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.