Use real variargs for variadic methods
authorDaimona Eaytoy <daimona.wiki@gmail.com>
Tue, 3 Sep 2019 16:01:04 +0000 (18:01 +0200)
committerReedy <reedy@wikimedia.org>
Fri, 18 Oct 2019 20:35:04 +0000 (21:35 +0100)
These were all checked via codesearch to ensure that nothing is overriding
these methods.

Change-Id: Ie2d8c1fd01478f46f3d0d1259417182b0d955a12

includes/Title.php
includes/language/Message.php
includes/libs/StatusValue.php
includes/user/User.php

index 6c15a06..60adb57 100644 (file)
@@ -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];
                }
index 35cc348..4a7228a 100644 (file)
@@ -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];
                }
index 4b381f8..4fcfffd 100644 (file)
@@ -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;
        }
index fc96fe1..2679e87 100644 (file)
@@ -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 );
        }
 
        /**