Docs: Explicitly return null when documented instead of void in filesystem and category functions.#10995
Conversation
…ilesystem and category functions. The @return tags for these functions indicate they may return `null`. This fixes "Missing return argument" warnings that PHPStan (level 1) and IDEs report when a bare `return;` is used in a function documented to return a typed value including `null`. Affected functions: - `WP_Filesystem()` in wp-admin/includes/file.php - `delete_plugins()` in wp-admin/includes/plugin.php (2 occurrences) - `delete_theme()` in wp-admin/includes/theme.php (2 occurrences) - `get_category_by_path()` in wp-includes/category.php No functional change. Follows the approach used in changeset 61281. See #64238.
|
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. |
|
Related: #8965 |
|
LGTM |
There was a problem hiding this comment.
Pull request overview
This pull request fixes PHPStan level 1 warnings and IDE type checking issues by ensuring functions explicitly return null when documented to do so, rather than implicitly returning void via bare return; statements. This improves static analysis compatibility and code clarity for functions that already document null as a possible return type in their @return tags.
Changes:
- Updated six early exit points across four WordPress core functions to explicitly return
nullinstead of using barereturn;statements - All affected functions already documented
nullas a valid return type in their PHPDoc@returntags - Changes align function implementations with their existing documentation
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/wp-includes/category.php |
Changed get_category_by_path() to explicitly return null when no categories are found |
src/wp-admin/includes/theme.php |
Changed delete_theme() to explicitly return null when filesystem credentials fail (2 occurrences) |
src/wp-admin/includes/plugin.php |
Changed delete_plugins() to explicitly return null when filesystem credentials fail (2 occurrences) |
src/wp-admin/includes/file.php |
Changed WP_Filesystem() to explicitly return null when filesystem method class file does not exist |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Note: These fix PHPStan rule level 3 issues. |
…id`. This fixes a PHPStan rule level 3 error: `return.empty`. Developed in #10995 Props huzaifaalmesbah, westonruter, shailu25, mukesh27, noruzzaman. See #64238. git-svn-id: https://develop.svn.wordpress.org/trunk@61716 602fd350-edb4-49c9-b593-d223f7449a82
…id`. This fixes a PHPStan rule level 3 error: `return.empty`. Developed in WordPress/wordpress-develop#10995 Props huzaifaalmesbah, westonruter, shailu25, mukesh27, noruzzaman. See #64238. Built from https://develop.svn.wordpress.org/trunk@61716 git-svn-id: http://core.svn.wordpress.org/trunk@61024 1a063a9b-81f0-0310-95a4-ce76da25c4cd
The
@returntags for these functions indicate they may returnnull.This fixes "Missing return argument" warnings that PHPStan (level 1) and IDEs report when a bare
return;is used in a function documented to return a typed value includingnull.Affected Functions and Files
WP_Filesystem()inwp-admin/includes/file.phpdelete_plugins()inwp-admin/includes/plugin.php(2 occurrences)delete_theme()inwp-admin/includes/theme.php(2 occurrences)get_category_by_path()inwp-includes/category.phpDetails
In each case, the function's
@returntag already documentsnullas a possible return value (e.g.@return bool|null|WP_Error), but the early exit paths used a barereturn;, which implicitly returnsvoid.Related: Trac #64238