Make WordPress Core

Changeset 46125


Ignore:
Timestamp:
09/15/2019 10:41:03 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Code Modernisation: Introduce the spread operator in wp-admin/includes/class-*-upgrader-skin.php.

Rather than relying func_get_args() to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

Props jrf.
See #47678.

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

Legend:

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

    r43571 r46125  
    5959        /**
    6060         * @param string|array|WP_Error $data
     61         * @param mixed                 ...$args Optional text replacements.
    6162         */
    62         public function feedback( $data ) {
     63        public function feedback( $data, ...$args ) {
    6364                if ( is_wp_error( $data ) ) {
    6465                        $string = $data->get_error_message();
    … …  
    7374
    7475                if ( strpos( $string, '%' ) !== false ) {
    75                         $args = func_get_args();
    76                         $args = array_splice( $args, 1 );
    7776                        if ( ! empty( $args ) ) {
    7877                                $string = vsprintf( $string, $args );
  • trunk/src/wp-admin/includes/class-bulk-upgrader-skin.php

    r45932 r46125  
    5151        /**
    5252         * @param string $string
     53         * @param mixed  ...$args Optional text replacements.
    5354         */
    54         public function feedback( $string ) {
     55        public function feedback( $string, ...$args ) {
    5556                if ( isset( $this->upgrader->strings[ $string ] ) ) {
    5657                        $string = $this->upgrader->strings[ $string ];
    … …  
    5859
    5960                if ( strpos( $string, '%' ) !== false ) {
    60                         $args = func_get_args();
    61                         $args = array_splice( $args, 1 );
    6261                        if ( $args ) {
    6362                                $args   = array_map( 'strip_tags', $args );
  • trunk/src/wp-admin/includes/class-wp-ajax-upgrader-skin.php

    r45487 r46125  
    7979         * @since 4.6.0
    8080         *
    81          * @param string|WP_Error $errors Errors.
     81         * @param string|WP_Error $errors  Errors.
     82         * @param mixed           ...$args Optional text replacements.
    8283         */
    83         public function error( $errors ) {
     84        public function error( $errors, ...$args ) {
    8485                if ( is_string( $errors ) ) {
    8586                        $string = $errors;
    … …  
    8990
    9091                        if ( false !== strpos( $string, '%' ) ) {
    91                                 $args = func_get_args();
    92                                 $args = array_splice( $args, 1 );
    9392                                if ( ! empty( $args ) ) {
    9493                                        $string = vsprintf( $string, $args );
    … …  
    105104                }
    106105
    107                 $args = func_get_args();
    108                 call_user_func_array( array( $this, 'parent::error' ), $args );
     106                parent::error( $errors, ...$args );
    109107        }
    110108
    … …  
    114112         * @since 4.6.0
    115113         *
    116          * @param string|array|WP_Error $data Log entry data.
     114         * @param string|array|WP_Error $data    Log entry data.
     115         * @param mixed                 ...$args Optional text replacements.
    117116         */
    118         public function feedback( $data ) {
     117        public function feedback( $data, ...$args ) {
    119118                if ( is_wp_error( $data ) ) {
    120119                        foreach ( $data->get_error_codes() as $error_code ) {
    … …  
    123122                }
    124123
    125                 $args = func_get_args();
    126                 call_user_func_array( array( $this, 'parent::feedback' ), $args );
     124                parent::feedback( $data, ...$args );
    127125        }
    128126}
  • trunk/src/wp-admin/includes/class-wp-upgrader-skin.php

    r44964 r46125  
    141141        /**
    142142         * @param string $string
    143          */
    144         public function feedback( $string ) {
     143         * @param mixed  ...$args Optional text replacements.
     144         */
     145        public function feedback( $string, ...$args ) {
    145146                if ( isset( $this->upgrader->strings[ $string ] ) ) {
    146147                        $string = $this->upgrader->strings[ $string ];
    … …  
    148149
    149150                if ( strpos( $string, '%' ) !== false ) {
    150                         $args = func_get_args();
    151                         $args = array_splice( $args, 1 );
    152151                        if ( $args ) {
    153152                                $args   = array_map( 'strip_tags', $args );
Note: See TracChangeset for help on using the changeset viewer.