Fix PHPStan return.empty errors in core methods#11017
Fix PHPStan return.empty errors in core methods#11017huzaifaalmesbah wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
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. |
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 PR addresses strict type
return.emptyviolations reported by PHPStan, ensuring methods return their declared or documented types rather than relying on an emptyreturn;.Details
src/wp-includes/class-wp-query.php(WP_Query::setup_postdata):true(success) andfalse(failure).return;bail-outs withreturn false;when the post object is invalid or whengenerate_postdata()fails.src/wp-includes/theme.php(_remove_theme_support):return;inside thecustom-header-uploadsbackward compatibility fallback withreturn true;. This matches the documentedboolreturn type to indicate the feature support was successfully removed.Why this is needed
Using empty
return;statements in methods/functions that have a declared or documented non-void return type causes static analysis tooling (like PHPStan) to flag them as errors. Returning explicit boolean values improves strict typing constraints and code clarity.Trac ticket: https://core.trac.wordpress.org/ticket/64238
Use of AI Tools
Use For PR Content.