WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/09/2021 06:35:34 PM (7 weeks ago)
Author:
hellofromTonya
Message:

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

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

Changes for readability:

  • @since clearly specifies the original parameter name and its new name as well as why the change happened.
  • In methods longer than a single line, the generic parameter is reassigned to the original parameter restoring it for context for use within the method. An inline comment is added to explain why this reassignment is made.

Follow-up to [38832], [39011], [39015], [39021], [39024], [39025], [39031], [39036], [43519], [43735], [43739], [43768], [46821], [48173], [48242], [49088], [50995], [51003], [51021].

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php

    r51705 r51786  
    263263     *
    264264     * @since 5.8.0
     265     * @since 5.9.0 Renamed `$raw_sidebar` to `$item` to match parent class for PHP 8 named parameter support.
    265266     *
    266267     * @global array $wp_registered_sidebars The registered sidebars.
    267268     * @global array $wp_registered_widgets  The registered widgets.
    268269     *
    269      * @param array           $raw_sidebar Sidebar instance.
    270      * @param WP_REST_Request $request     Full details about the request.
     270     * @param array           $item    Sidebar instance.
     271     * @param WP_REST_Request $request Full details about the request.
    271272     * @return WP_REST_Response Prepared response object.
    272273     */
    273     public function prepare_item_for_response( $raw_sidebar, $request ) {
     274    public function prepare_item_for_response( $item, $request ) {
    274275        global $wp_registered_sidebars, $wp_registered_widgets;
    275276
    276         $id      = $raw_sidebar['id'];
    277         $sidebar = array( 'id' => $id );
     277        // Restores the more descriptive, specific name for use within this method.
     278        $raw_sidebar = $item;
     279        $id          = $raw_sidebar['id'];
     280        $sidebar     = array( 'id' => $id );
    278281
    279282        if ( isset( $wp_registered_sidebars[ $id ] ) ) {
Note: See TracChangeset for help on using the changeset viewer.