Skip to content

Comments

Docs: Explicitly return null when documented instead of void in filesystem and category functions.#10995

Closed
huzaifaalmesbah wants to merge 1 commit intoWordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-explicit-return-null
Closed

Docs: Explicitly return null when documented instead of void in filesystem and category functions.#10995
huzaifaalmesbah wants to merge 1 commit intoWordPress:trunkfrom
huzaifaalmesbah:fix/phpstan-explicit-return-null

Conversation

@huzaifaalmesbah
Copy link
Member

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 and Files

  • 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

Details

In each case, the function's @return tag already documents null as a possible return value (e.g. @return bool|null|WP_Error), but the early exit paths used a bare return;, which implicitly returns void.

Related: Trac #64238

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

github-actions bot commented Feb 21, 2026

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, westonruter, shailu25, mukesh27, noruzzaman.

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.

@westonruter
Copy link
Member

Related: #8965

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@shail-mehta shail-mehta left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@noruzzamans
Copy link

LGTM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 null instead of using bare return; statements
  • All affected functions already documented null as a valid return type in their PHPDoc @return tags
  • 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.

@westonruter
Copy link
Member

Note: These fix PHPStan rule level 3 issues.

pento pushed a commit that referenced this pull request Feb 23, 2026
…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
@westonruter
Copy link
Member

Committed in r61716 (954c187)

markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Feb 23, 2026
…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
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.

5 participants