From 817049ec6b1824513d57375676d478dfeac8ff2c Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Thu, 19 Apr 2018 14:11:28 -0700 Subject: [PATCH] Begin introducing PHP 5.6 variadic parameters where appropriate Change-Id: I5670b8482e8d3bcb0b3a2b4d2ce9834cfc37e171 --- includes/GlobalFunctions.php | 15 ++++++--------- includes/shell/Shell.php | 18 ++++++++---------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 8fcd11ef82..ae09602995 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1336,21 +1336,19 @@ function wfGetLangObj( $langcode = false ) { * This function replaces all old wfMsg* functions. * * @param string|string[]|MessageSpecifier $key Message key, or array of keys, or a MessageSpecifier - * @param mixed $params,... Normal message parameters + * @param string ...$params Normal message parameters * @return Message * * @since 1.17 * * @see Message::__construct */ -function wfMessage( $key /*...*/ ) { +function wfMessage( $key, ...$params ) { $message = new Message( $key ); // We call Message::params() to reduce code duplication - $params = func_get_args(); - array_shift( $params ); if ( $params ) { - call_user_func_array( [ $message, 'params' ], $params ); + $message->params( ...$params ); } return $message; @@ -1361,16 +1359,15 @@ function wfMessage( $key /*...*/ ) { * for the first message which is non-empty. If all messages are empty then an * instance of the first message key is returned. * - * @param string|string[] $keys,... Message keys + * @param string|string[] ...$keys Message keys * @return Message * * @since 1.18 * * @see Message::newFallbackSequence */ -function wfMessageFallback( /*...*/ ) { - $args = func_get_args(); - return call_user_func_array( 'Message::newFallbackSequence', $args ); +function wfMessageFallback( ...$keys ) { + return Message::newFallbackSequence( ...$keys ); } /** diff --git a/includes/shell/Shell.php b/includes/shell/Shell.php index 3f10c11a32..ee9f1ebbf7 100644 --- a/includes/shell/Shell.php +++ b/includes/shell/Shell.php @@ -110,23 +110,22 @@ class Shell { /** * Returns a new instance of Command class * - * @param string|string[] $command String or array of strings representing the command to + * @param string|string[] ...$commands String or array of strings representing the command to * be executed, each value will be escaped. * Example: [ 'convert', '-font', 'font name' ] would produce "'convert' '-font' 'font name'" * @return Command */ - public static function command( $command ) { - $args = func_get_args(); - if ( count( $args ) === 1 && is_array( reset( $args ) ) ) { + public static function command( ...$commands ) { + if ( count( $commands ) === 1 && is_array( reset( $commands ) ) ) { // If only one argument has been passed, and that argument is an array, // treat it as a list of arguments - $args = reset( $args ); + $commands = reset( $commands ); } $command = MediaWikiServices::getInstance() ->getShellCommandFactory() ->create(); - return $command->params( $args ); + return $command->params( $commands ); } /** @@ -156,12 +155,11 @@ class Shell { * (https://bugs.php.net/bug.php?id=26285) and the locale problems on Linux in * PHP 5.2.6+ (bug backported to earlier distro releases of PHP). * - * @param string $args,... strings to escape and glue together, or a single array of - * strings parameter. Null values are ignored. + * @param string|string[] ...$args strings to escape and glue together, or a single + * array of strings parameter. Null values are ignored. * @return string */ - public static function escape( /* ... */ ) { - $args = func_get_args(); + public static function escape( ...$args ) { if ( count( $args ) === 1 && is_array( reset( $args ) ) ) { // If only one argument has been passed, and that argument is an array, // treat it as a list of arguments -- 2.20.1