Make WordPress Core

Changeset 51781


Ignore:
Timestamp:
09/09/2021 01:47:17 PM (5 years ago)
Author:
hellofromTonya
Message:

Code Modernization: Fix reserved keyword and parameter name mismatches for parent/child classes in WP_Upgrader_Skin::feedback().

In the parent class, renames the parameter $string to $feedback.
Why? string is a PHP reserved keyword.

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.

Changes for readability:

  • @since clearly specifies the original parameter name and its new name as well as why the change happened.

Follow-up to [11005], [25228], [30680], [32655], [38199], [49596].

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

Location:
trunk/src/wp-admin/includes
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-automatic-upgrader-skin.php

    r50828 r51781  
    6767         *
    6868         * @since 3.7.0
     69         * @since 5.9.0 Renamed `$data` to `$feedback` for PHP 8 named parameter support.
    6970         *
    70          * @param string|array|WP_Error $data    Message data.
    71          * @param mixed                 ...$args Optional text replacements.
     71         * @param string|array|WP_Error $feedback Message data.
     72         * @param mixed                 ...$args  Optional text replacements.
    7273         */
    73         public function feedback( $data, ...$args ) {
    74                 if ( is_wp_error( $data ) ) {
    75                         $string = $data->get_error_message();
    76                 } elseif ( is_array( $data ) ) {
     74        public function feedback( $feedback, ...$args ) {
     75                if ( is_wp_error( $feedback ) ) {
     76                        $string = $feedback->get_error_message();
     77                } elseif ( is_array( $feedback ) ) {
    7778                        return;
    7879                } else {
    79                         $string = $data;
     80                        $string = $feedback;
    8081                }
     82
    8183                if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
    8284                        $string = $this->upgrader->strings[ $string ];
  • trunk/src/wp-admin/includes/class-bulk-upgrader-skin.php

    r46125 r51781  
    5050
    5151        /**
    52          * @param string $string
    53          * @param mixed  ...$args Optional text replacements.
     52         * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
     53         *
     54         * @param string $feedback Message data.
     55         * @param mixed  ...$args  Optional text replacements.
    5456         */
    55         public function feedback( $string, ...$args ) {
    56                 if ( isset( $this->upgrader->strings[ $string ] ) ) {
    57                         $string = $this->upgrader->strings[ $string ];
     57        public function feedback( $feedback, ...$args ) {
     58                if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
     59                        $feedback = $this->upgrader->strings[ $feedback ];
    5860                }
    5961
    60                 if ( strpos( $string, '%' ) !== false ) {
     62                if ( strpos( $feedback, '%' ) !== false ) {
    6163                        if ( $args ) {
    62                                 $args   = array_map( 'strip_tags', $args );
    63                                 $args   = array_map( 'esc_html', $args );
    64                                 $string = vsprintf( $string, $args );
     64                                $args     = array_map( 'strip_tags', $args );
     65                                $args     = array_map( 'esc_html', $args );
     66                                $feedback = vsprintf( $feedback, $args );
    6567                        }
    6668                }
    67                 if ( empty( $string ) ) {
     69                if ( empty( $feedback ) ) {
    6870                        return;
    6971                }
    7072                if ( $this->in_loop ) {
    71                         echo "$string<br />\n";
     73                        echo "$feedback<br />\n";
    7274                } else {
    73                         echo "<p>$string</p>\n";
     75                        echo "<p>$feedback</p>\n";
    7476                }
    7577        }
  • trunk/src/wp-admin/includes/class-wp-ajax-upgrader-skin.php

    r49596 r51781  
    122122         * @since 5.3.0 Formalized the existing `...$args` parameter by adding it
    123123         *              to the function signature.
     124         * @since 5.9.0 Renamed `$data` to `$feedback` for PHP 8 named parameter support.
    124125         *
    125          * @param string|array|WP_Error $data    Message data.
    126          * @param mixed                 ...$args Optional text replacements.
     126         * @param string|array|WP_Error $feedback Message data.
     127         * @param mixed                 ...$args  Optional text replacements.
    127128         */
    128         public function feedback( $data, ...$args ) {
    129                 if ( is_wp_error( $data ) ) {
    130                         foreach ( $data->get_error_codes() as $error_code ) {
    131                                 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
     129        public function feedback( $feedback, ...$args ) {
     130                if ( is_wp_error( $feedback ) ) {
     131                        foreach ( $feedback->get_error_codes() as $error_code ) {
     132                                $this->errors->add( $error_code, $feedback->get_error_message( $error_code ), $feedback->get_error_data( $error_code ) );
    132133                        }
    133134                }
    134135
    135                 parent::feedback( $data, ...$args );
     136                parent::feedback( $feedback, ...$args );
    136137        }
    137138}
  • trunk/src/wp-admin/includes/class-wp-upgrader-skin.php

    r49675 r51781  
    187187        /**
    188188         * @since 2.8.0
    189          *
    190          * @param string $string
    191          * @param mixed  ...$args Optional text replacements.
    192          */
    193         public function feedback( $string, ...$args ) {
    194                 if ( isset( $this->upgrader->strings[ $string ] ) ) {
    195                         $string = $this->upgrader->strings[ $string ];
    196                 }
    197 
    198                 if ( strpos( $string, '%' ) !== false ) {
     189         * @since 5.9.0 Renamed `$string` (a PHP reserved keyword) to `$feedback` for PHP 8 named parameter support.
     190         *
     191         * @param string $feedback Message data.
     192         * @param mixed  ...$args  Optional text replacements.
     193         */
     194        public function feedback( $feedback, ...$args ) {
     195                if ( isset( $this->upgrader->strings[ $feedback ] ) ) {
     196                        $feedback = $this->upgrader->strings[ $feedback ];
     197                }
     198
     199                if ( strpos( $feedback, '%' ) !== false ) {
    199200                        if ( $args ) {
    200                                 $args   = array_map( 'strip_tags', $args );
    201                                 $args   = array_map( 'esc_html', $args );
    202                                 $string = vsprintf( $string, $args );
     201                                $args     = array_map( 'strip_tags', $args );
     202                                $args     = array_map( 'esc_html', $args );
     203                                $feedback = vsprintf( $feedback, $args );
    203204                        }
    204205                }
    205                 if ( empty( $string ) ) {
    206                         return;
    207                 }
    208                 show_message( $string );
     206                if ( empty( $feedback ) ) {
     207                        return;
     208                }
     209                show_message( $feedback );
    209210        }
    210211
Note: See TracChangeset for help on using the changeset viewer.