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.
Built from https://develop.svn.wordpress.org/trunk@46125


git-svn-id: http://core.svn.wordpress.org/trunk@45937 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2019-09-15 10:42:54 +00:00
parent 300b14e1ca
commit 340b7b53c8
5 changed files with 15 additions and 20 deletions

View File

@@ -78,9 +78,10 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
*
* @since 4.6.0
*
* @param string|WP_Error $errors Errors.
* @param string|WP_Error $errors Errors.
* @param mixed ...$args Optional text replacements.
*/
public function error( $errors ) {
public function error( $errors, ...$args ) {
if ( is_string( $errors ) ) {
$string = $errors;
if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
@@ -88,8 +89,6 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
}
if ( false !== strpos( $string, '%' ) ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( ! empty( $args ) ) {
$string = vsprintf( $string, $args );
}
@@ -104,8 +103,7 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
}
}
$args = func_get_args();
call_user_func_array( array( $this, 'parent::error' ), $args );
parent::error( $errors, ...$args );
}
/**
@@ -113,16 +111,16 @@ class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
*
* @since 4.6.0
*
* @param string|array|WP_Error $data Log entry data.
* @param string|array|WP_Error $data Log entry data.
* @param mixed ...$args Optional text replacements.
*/
public function feedback( $data ) {
public function feedback( $data, ...$args ) {
if ( is_wp_error( $data ) ) {
foreach ( $data->get_error_codes() as $error_code ) {
$this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
}
}
$args = func_get_args();
call_user_func_array( array( $this, 'parent::feedback' ), $args );
parent::feedback( $data, ...$args );
}
}