Make WordPress Core

Opened 5 weeks ago

Last modified 6 days ago

#63268 accepted defect (bug)

PHPStan code quality improvements for 6.9

Reported by: justlevine's profile justlevine Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.9 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch
Focuses: coding-standards Cc:

Description (last modified by SergeyBiryukov)

This ticket is for various code quality issues and improvements surfaced via PHPStan.

Implementing PHPStan is tracked separately in #61175.

Previously (latest first)

Change History (35)

#1 @justlevine
5 weeks ago

Crossposted stats from #61175 using https://github.com/WordPress/wordpress-develop/pull/7619, so there's a quick reference for comparison when this ticket gets closed for WP7.0

(even if today's trunk isn't 100% synonymous with 6.9)

As of 12 April 2025 (based on https://github.com/WordPress/wordpress-develop/commit/4ce25a5b915ce4409fb6339b8b1ce46fc10aeb0a )

(Previous rebase: 21 Feb 25 https://github.com/WordPress/wordpress-develop/commit/165d803380c561f39caeb0cbdc44f5c06c988cba )

PHPStan Level Error Count New Remediated
0 14 - -
1 65 - 5
2 326 1 2
3 195 5 -
4 985 6 1
5 557 8 5
6 2134 3 0

This ticket was mentioned in PR #8680 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#2

  • Keywords has-patch added

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This PR fixes the parameter doc-type on WP_REST_Server::get_index()'s $request param to be a WP_REST_Request instead of an array.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

This ticket was mentioned in PR #8681 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#3

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This PR updates _wp_filter_build_unique_id() to explicitly return null if the function isn't passed a valid $callback. This is instead of the current behavior where the function can return void, but is typed as only returning a string.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

#4 @SergeyBiryukov
5 weeks ago

  • Description modified (diff)
  • Focuses coding-standards added
  • Milestone changed from Awaiting Review to 6.9
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

This ticket was mentioned in PR #8384 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#5

This PR fixes the default $post ID param values used in several functions in wp-includes/link-template.php, to bring them in line with their int doctypes (and the doctypes of their internal function calls).

More specifically,

  • get_page_link(): $post = false changed to $post = 0
  • _get_page_link(): $post = false changed to $post = 0
  • post_comments_feed_link(): $post_id = '' changed to $post_id = 0

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8385 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#6

This PR updates the @param types on get_comments_number_text() to correctly reflect the default false parameter.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8386 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#7

This PR fixes the doc-block for rest_menu_read_access, where the third param name is incorrectly named $this, which is an illegal parameter name.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8387 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#8

This PR fixes the default $site_id parameter value used throughout WP_User to correctly match the (int) doctypes, and the doctypes of the functions they use internally.

Specifically:

  • __construct(): $site_id = '' is now $site_id = 0
  • init(): $site_id = '' is now $site_id = 0
  • for_blog(): $blog_id = '' is now $blog_id = 0
  • for_site(): $site_id = '' is now $site_id = 0

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8388 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#9

This PR fixes an issue in wp_xmlrpc_server::wp_deleteTerm() doesn't correctly return the WP_Error message from the wp_delete_term() attempt.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8389 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#10

This PR fixes the WP_Meta_Query constructor arg, to take a default value of array(), as specified by the doc-block @param .

Since the function is gated with a loose, falsy ! $meta_query check, there is no difference to function behavior.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8390 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#11

This PR updates the @return type for _wp_get_current_user() to correctly reflect that it can return a null value if no user is logged in.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #7720 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#12

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This PR fixes an issue in get_taxonomy_labels(), where the template_name was accessed as an object property on $tax->labels instead of as an array property.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

#13 @SergeyBiryukov
5 weeks ago

In 60152:

Coding Standards: Correct $post parameter default values in link-template.php.

This commit corrects the default post ID parameter values used in several functions to bring them in line with their int doctypes (and the doctypes of their internal function calls).

More specifically,

  • get_page_link(): $post = false changed to $post = 0
  • _get_page_link(): $post = false changed to $post = 0
  • post_comments_feed_link(): $post_id = '' changed to $post_id = 0

Follow-up to [1752], [4475], [6365], [9136], [9274], [21735], [24490], [32606], [37252].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8384:


5 weeks ago
#14

Thanks for the PR! Merged in r60152.

This ticket was mentioned in PR #8682 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#15

This PR fixes a bug in WP_Debug_Data::get_wp_themes_inactive(), where the update_themes site $transient was not defined before being checked in several isset() checks later on in the function (L1359).

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

This ticket was mentioned in PR #8683 on WordPress/wordpress-develop by @justlevine.


5 weeks ago
#16

This PR updates wp_get_nav_menu_to_edit() to explicitly return null and adds null to the function's return type. This is instead of the existing behavior where the implict void return is not typehinted.

While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.

Trac ticket: https://core.trac.wordpress.org/ticket/63268

#17 @SergeyBiryukov
4 weeks ago

In 60166:

Docs: Correct parameter types for get_comments_number_text().

This updates the @param types to correctly reflect the default false parameter.

Follow-up to [6495], [25567], [28912], [49936].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8385:


4 weeks ago
#18

Thanks for the PR! Merged in r60166.

#19 @SergeyBiryukov
4 weeks ago

In 60172:

Docs: Correct parameter name for rest_menu_read_access filter.

The filter's third parameter was incorrectly named $this, which is not a valid parameter name.

Follow-up to [59718], [59734].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8386:


4 weeks ago
#20

Thanks for the PR! Merged in r60172.

#21 @SergeyBiryukov
4 weeks ago

In 60174:

Coding Standards: Correct $site_id parameter default values in WP_User.

This commit corrects the default $site_id parameter values used throughout the WP_User class to bring them in line with their int doctypes (and the doctypes of the functions used internally by the affected class methods).

More specifically,

  • __construct(): $site_id = '' changed to $site_id = 0
  • init(): $site_id = '' changed to $site_id = 0
  • for_blog(): $blog_id = '' changed to $blog_id = 0
  • for_site(): $site_id = '' changed to $site_id = 0

Follow-up to [12796], [15566], [18597], [41624].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8387:


4 weeks ago
#22

Thanks for the PR! Merged in r60174.

#23 @SergeyBiryukov
4 weeks ago

In 60175:

XML-RPC: Correctly return deletion error message in wp_xmlrpc_server::wp_deleteTerm().

This ensures that the correct variable is used to return the WP_Error message from the wp_delete_term() attempt.

Follow-up to [20137].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8388:


4 weeks ago
#24

Thanks for the PR! Merged in r60175.

#25 @SergeyBiryukov
3 weeks ago

In 60176:

Coding Standards: Correct default parameter type in WP_Meta_Query::__construct().

This adjusts the default $meta_query parameter value to match the documented type of array.

Since the function is gated with a loose, falsey ! $meta_query check, there is no difference to function behavior.

Follow-up to [17699].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8389:


3 weeks ago
#26

Thanks for the PR! Merged in r60176.

#27 @SergeyBiryukov
3 weeks ago

In 60177:

Docs: Correct $request parameter type in WP_REST_Server::get_index().

Follow-up to [34928], [52796].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8680:


3 weeks ago
#28

Thanks for the PR! Merged in r60177.

#29 @SergeyBiryukov
3 weeks ago

In 60179:

Coding Standards: Explicitly return null in _wp_filter_build_unique_id().

This commit updates the function to explicitly return null if a valid $callback is not passed. Previously, the function could return void, but was typed as only returning a string.

Follow-up to [5936], [11409], [12090], [46220], [46801], [50807], [52300].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8681:


3 weeks ago
#30

Thanks for the PR! Merged in r60179.

#31 @SergeyBiryukov
3 weeks ago

In 60180:

Coding Standards: Explicitly return null in wp_get_nav_menu_to_edit().

This commit updates the function to explicitly return null if a valid $menu_id is not passed or the term does not exist. Previously, the function could return void, but was typed as only returning a string or a WP_Error object.

Follow-up to [14248].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8683:


3 weeks ago
#32

Thanks for the PR! Merged in r60180.

#33 @SergeyBiryukov
3 weeks ago

In 60181:

Site Health: Set missing $transient in WP_Debug_Data:get_wp_themes_inactive().

This commit addresses a bug where the update_themes site transient was not defined before being checked in several isset() checks later on in the method.

Follow-up to [59176].

Props justlevine.
See #63268.

@SergeyBiryukov commented on PR #8682:


12 days ago
#34

Thanks for the PR! Merged in r60181.

@justlevine commented on PR #7720:


6 days ago
#35

On further investigation, this is invalid, and labels is indeed reconverted back to an object.

Note: See TracTickets for help on using tickets.