WordPress.org

Make WordPress Core

Changeset 51787


Ignore:
Timestamp:
09/09/2021 07:20:56 PM (3 weeks ago)
Author:
hellofromTonya
Message:

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

In each child and grandchild class, renames the second 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.

Follow-up to [48072].

Props jrf, hellofromTonya, sergeybiryukov, azaozz, desrosj, johnbillion.
See #51553.

Location:
trunk/src/wp-includes/sitemaps/providers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-posts.php

    r48476 r51787  
    5454     *
    5555     * @since 5.5.0
    56      *
    57      * @param int    $page_num  Page of results.
    58      * @param string $post_type Optional. Post type name. Default empty.
     56     * @since 5.9.0 Renamed `$post_type` to `$object_subtype` to match parent class
     57     *              for PHP 8 named parameter support.
     58     *
     59     * @param int    $page_num       Page of results.
     60     * @param string $object_subtype Optional. Post type name. Default empty.
     61     *
    5962     * @return array Array of URLs for a sitemap.
    6063     */
    61     public function get_url_list( $page_num, $post_type = '' ) {
     64    public function get_url_list( $page_num, $object_subtype = '' ) {
     65        // Restores the more descriptive, specific name for use within this method.
     66        $post_type = $object_subtype;
     67
    6268        // Bail early if the queried post type is not supported.
    6369        $supported_types = $this->get_object_subtypes();
  • trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-taxonomies.php

    r49137 r51787  
    5252     *
    5353     * @since 5.5.0
    54      *
    55      * @param int    $page_num Page of results.
    56      * @param string $taxonomy Optional. Taxonomy name. Default empty.
     54     * @since 5.9.0 Renamed `$taxonomy` to `$object_subtype` to match parent class
     55     *              for PHP 8 named parameter support.
     56     *
     57     * @param int    $page_num       Page of results.
     58     * @param string $object_subtype Optional. Taxonomy name. Default empty.
    5759     * @return array Array of URLs for a sitemap.
    5860     */
    59     public function get_url_list( $page_num, $taxonomy = '' ) {
     61    public function get_url_list( $page_num, $object_subtype = '' ) {
     62        // Restores the more descriptive, specific name for use within this method.
     63        $taxonomy        = $object_subtype;
    6064        $supported_types = $this->get_object_subtypes();
    6165
Note: See TracChangeset for help on using the changeset viewer.