From 248b7e2e31a4c8c4034c885d7ea5d07fe9f7d111 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 3 Sep 2019 18:01:04 +0200 Subject: [PATCH] Use real variargs for variadic methods These were all checked via codesearch to ensure that nothing is overriding these methods. Change-Id: Ie2d8c1fd01478f46f3d0d1259417182b0d955a12 --- includes/Title.php | 6 ++-- includes/language/Message.php | 60 +++++++++++++---------------------- includes/libs/StatusValue.php | 21 ++++++------ includes/user/User.php | 14 ++++---- 4 files changed, 42 insertions(+), 59 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 6c15a062b0..60adb570fe 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1266,13 +1266,11 @@ class Title implements LinkTarget, IDBAccessObject { /** * Returns true if the title is inside one of the specified namespaces. * - * @param int|int[] $namespaces,... The namespaces to check for + * @param int|int[] ...$namespaces The namespaces to check for * @return bool * @since 1.19 - * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ - public function inNamespaces( /* ... */ ) { - $namespaces = func_get_args(); + public function inNamespaces( ...$namespaces ) { if ( count( $namespaces ) > 0 && is_array( $namespaces[0] ) ) { $namespaces = $namespaces[0]; } diff --git a/includes/language/Message.php b/includes/language/Message.php index 35cc34881d..4a7228ae32 100644 --- a/includes/language/Message.php +++ b/includes/language/Message.php @@ -158,8 +158,6 @@ use MediaWiki\MediaWikiServices; * @see https://www.mediawiki.org/wiki/Localisation * * @since 1.17 - * @phan-file-suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, - * T191668#5263929 */ class Message implements MessageSpecifier, Serializable { /** Use message text as-is */ @@ -405,14 +403,11 @@ class Message implements MessageSpecifier, Serializable { * @since 1.17 * * @param string|string[]|MessageSpecifier $key - * @param mixed $param,... Parameters as strings. - * @suppress PhanCommentParamWithoutRealParam HHVM bug T228695#5450847 + * @param mixed ...$params Parameters as strings. * * @return Message */ - public static function newFromKey( $key /*...*/ ) { - $params = func_get_args(); - array_shift( $params ); + public static function newFromKey( $key, ...$params ) { return new self( $key, $params ); } @@ -457,13 +452,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.18 * - * @param string|string[] $keys,... Message keys, or first argument as an array of all the + * @param string|string[] ...$keys Message keys, or first argument as an array of all the * message keys. * * @return Message */ - public static function newFallbackSequence( /*...*/ ) { - $keys = func_get_args(); + public static function newFallbackSequence( ...$keys ) { if ( func_num_args() == 1 ) { if ( is_array( $keys[0] ) ) { // Allow an array to be passed as the first argument instead @@ -508,14 +502,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.17 * - * @param mixed $args,... Parameters as strings or arrays from + * @param mixed ...$args Parameters as strings or arrays from * Message::numParam() and the like, or a single array of parameters. * * @return Message $this */ - public function params( /*...*/ ) { - $args = func_get_args(); - + public function params( ...$args ) { // If $args has only one entry and it's an array, then it's either a // non-varargs call or it happens to be a call with just a single // "special" parameter. Since the "special" parameters don't have any @@ -545,13 +537,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.17 * - * @param mixed $params,... Raw parameters as strings, or a single argument that is + * @param mixed ...$params Raw parameters as strings, or a single argument that is * an array of raw parameters. * * @return Message $this */ - public function rawParams( /*...*/ ) { - $params = func_get_args(); + public function rawParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -567,13 +558,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.18 * - * @param mixed $param,... Numeric parameters, or a single argument that is + * @param mixed ...$params Numeric parameters, or a single argument that is * an array of numeric parameters. * * @return Message $this */ - public function numParams( /*...*/ ) { - $params = func_get_args(); + public function numParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -589,13 +579,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.22 * - * @param int|int[] $param,... Duration parameters, or a single argument that is + * @param int|int[] ...$params Duration parameters, or a single argument that is * an array of duration parameters. * * @return Message $this */ - public function durationParams( /*...*/ ) { - $params = func_get_args(); + public function durationParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -611,13 +600,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.22 * - * @param string|string[] $param,... Expiry parameters, or a single argument that is + * @param string|string[] ...$params Expiry parameters, or a single argument that is * an array of expiry parameters. * * @return Message $this */ - public function expiryParams( /*...*/ ) { - $params = func_get_args(); + public function expiryParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -633,13 +621,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.22 * - * @param int|int[] $param,... Time period parameters, or a single argument that is + * @param int|int[] ...$params Time period parameters, or a single argument that is * an array of time period parameters. * * @return Message $this */ - public function timeperiodParams( /*...*/ ) { - $params = func_get_args(); + public function timeperiodParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -655,13 +642,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.22 * - * @param int|int[] $param,... Size parameters, or a single argument that is + * @param int|int[] ...$params Size parameters, or a single argument that is * an array of size parameters. * * @return Message $this */ - public function sizeParams( /*...*/ ) { - $params = func_get_args(); + public function sizeParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -677,13 +663,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.22 * - * @param int|int[] $param,... Bit rate parameters, or a single argument that is + * @param int|int[] ...$params Bit rate parameters, or a single argument that is * an array of bit rate parameters. * * @return Message $this */ - public function bitrateParams( /*...*/ ) { - $params = func_get_args(); + public function bitrateParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } @@ -701,13 +686,12 @@ class Message implements MessageSpecifier, Serializable { * * @since 1.25 * - * @param string|string[] $param,... plaintext parameters, or a single argument that is + * @param string|string[] ...$params plaintext parameters, or a single argument that is * an array of plaintext parameters. * * @return Message $this */ - public function plaintextParams( /*...*/ ) { - $params = func_get_args(); + public function plaintextParams( ...$params ) { if ( isset( $params[0] ) && is_array( $params[0] ) ) { $params = $params[0]; } diff --git a/includes/libs/StatusValue.php b/includes/libs/StatusValue.php index 4b381f8de1..4fcfffd8d3 100644 --- a/includes/libs/StatusValue.php +++ b/includes/libs/StatusValue.php @@ -63,12 +63,12 @@ class StatusValue { * Factory function for fatal errors * * @param string|MessageSpecifier $message Message key or object + * @param mixed ...$parameters * @return static */ - public static function newFatal( $message /*, parameters...*/ ) { - $params = func_get_args(); + public static function newFatal( $message, ...$parameters ) { $result = new static(); - $result->fatal( ...$params ); + $result->fatal( $message, ...$parameters ); return $result; } @@ -173,12 +173,13 @@ class StatusValue { * Add a new warning * * @param string|MessageSpecifier $message Message key or object + * @param mixed ...$parameters */ - public function warning( $message /*, parameters... */ ) { + public function warning( $message, ...$parameters ) { $this->errors[] = [ 'type' => 'warning', 'message' => $message, - 'params' => array_slice( func_get_args(), 1 ) + 'params' => $parameters ]; } @@ -187,12 +188,13 @@ class StatusValue { * This can be used for non-fatal errors * * @param string|MessageSpecifier $message Message key or object + * @param mixed ...$parameters */ - public function error( $message /*, parameters... */ ) { + public function error( $message, ...$parameters ) { $this->errors[] = [ 'type' => 'error', 'message' => $message, - 'params' => array_slice( func_get_args(), 1 ) + 'params' => $parameters ]; } @@ -201,12 +203,13 @@ class StatusValue { * as a whole was fatal * * @param string|MessageSpecifier $message Message key or object + * @param mixed ...$parameters */ - public function fatal( $message /*, parameters... */ ) { + public function fatal( $message, ...$parameters ) { $this->errors[] = [ 'type' => 'error', 'message' => $message, - 'params' => array_slice( func_get_args(), 1 ) + 'params' => $parameters ]; $this->ok = false; } diff --git a/includes/user/User.php b/includes/user/User.php index fc96fe1952..2679e87c64 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -3554,27 +3554,25 @@ class User implements IDBAccessObject, UserIdentity { * @deprecated since 1.34, use MediaWikiServices::getInstance() * ->getPermissionManager()->userHasAnyRights(...) instead * - * @param string $permissions,... Permissions to test + * @param string ...$permissions Permissions to test * @return bool True if user is allowed to perform *any* of the given actions - * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ - public function isAllowedAny() { + public function isAllowedAny( ...$permissions ) { return MediaWikiServices::getInstance() ->getPermissionManager() - ->userHasAnyRight( $this, ...func_get_args() ); + ->userHasAnyRight( $this, ...$permissions ); } /** * @deprecated since 1.34, use MediaWikiServices::getInstance() * ->getPermissionManager()->userHasAllRights(...) instead - * @param string $permissions,... Permissions to test + * @param string ...$permissions Permissions to test * @return bool True if the user is allowed to perform *all* of the given actions - * @suppress PhanCommentParamOnEmptyParamList Cannot make variadic due to HHVM bug, T191668#5263929 */ - public function isAllowedAll() { + public function isAllowedAll( ...$permissions ) { return MediaWikiServices::getInstance() ->getPermissionManager() - ->userHasAllRights( $this, ...func_get_args() ); + ->userHasAllRights( $this, ...$permissions ); } /** -- 2.20.1