Code Modernization: Fix parameter name mismatches for parent/child classes in `WP_Sitemaps_Provider::get_max_num_pages()`.

In each child class, renames the parameter to match the parent's method signature.
Why? PHP 8 introduces the ability to pass named arguments to function/method calls. This means the child and parent method signatures (i.e. parameter names) need to match.

Adds @since to clearly specify why the change happened.

Reassigns the generic parameter to the original parameter.
Why? Restoring the original name keeps the context intact within the method and makes the code more readable. An inline comment explains why this reassignment is made.

Note: Reassignment is done after the guard clause.
Why? To avoid unnecessary processing and memory should the method bail out.

Follow-up to [48072].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.
Built from https://develop.svn.wordpress.org/trunk@51788


git-svn-id: http://core.svn.wordpress.org/trunk@51395 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
hellofromTonya 2021-09-09 19:42:56 +00:00
parent a4b163a674
commit f2f05f8e04
3 changed files with 17 additions and 7 deletions

View File

@ -148,15 +148,20 @@ class WP_Sitemaps_Posts extends WP_Sitemaps_Provider {
* Gets the max number of pages available for the object type.
*
* @since 5.5.0
* @since 5.9.0 Renamed `$post_type` to `$object_subtype` to match parent class
* for PHP 8 named parameter support.
*
* @param string $post_type Optional. Post type name. Default empty.
* @param string $object_subtype Optional. Post type name. Default empty.
* @return int Total number of pages.
*/
public function get_max_num_pages( $post_type = '' ) {
if ( empty( $post_type ) ) {
public function get_max_num_pages( $object_subtype = '' ) {
if ( empty( $object_subtype ) ) {
return 0;
}
// Restores the more descriptive, specific name for use within this method.
$post_type = $object_subtype;
/**
* Filters the max number of pages before it is generated.
*

View File

@ -134,15 +134,20 @@ class WP_Sitemaps_Taxonomies extends WP_Sitemaps_Provider {
* Gets the max number of pages available for the object type.
*
* @since 5.5.0
* @since 5.9.0 Renamed `$taxonomy` to `$object_subtype` to match parent class
* for PHP 8 named parameter support.
*
* @param string $taxonomy Taxonomy name.
* @param string $object_subtype Optional. Taxonomy name. Default empty.
* @return int Total number of pages.
*/
public function get_max_num_pages( $taxonomy = '' ) {
if ( empty( $taxonomy ) ) {
public function get_max_num_pages( $object_subtype = '' ) {
if ( empty( $object_subtype ) ) {
return 0;
}
// Restores the more descriptive, specific name for use within this method.
$taxonomy = $object_subtype;
/**
* Filters the max number of pages before it is generated.
*

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-51787';
$wp_version = '5.9-alpha-51788';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.