Skip to content

Comments

Fix PHPStan return.empty errors in core methods#11017

Open
huzaifaalmesbah wants to merge 1 commit intoWordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-return-empty-core
Open

Fix PHPStan return.empty errors in core methods#11017
huzaifaalmesbah wants to merge 1 commit intoWordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-return-empty-core

Conversation

@huzaifaalmesbah
Copy link
Member

This PR addresses strict type return.empty violations reported by PHPStan, ensuring methods return their declared or documented types rather than relying on an empty return;.
Details

  • src/wp-includes/class-wp-query.php (WP_Query::setup_postdata):
    • Updated the PHPDoc to reflect that the method can return both true (success) and false (failure).
    • Replaced the early empty return; bail-outs with return false; when the post object is invalid or when generate_postdata() fails.
  • src/wp-includes/theme.php (_remove_theme_support):
    • Replaced an empty return; inside the custom-header-uploads backward compatibility fallback with return true;. This matches the documented bool return 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.

@github-actions
Copy link

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 huzaifaalmesbah.

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

@github-actions
Copy link

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.

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.

1 participant