Replace call_user_func_array(), part 1
authorMax Semenik <maxsem.wiki@gmail.com>
Tue, 5 Jun 2018 06:24:34 +0000 (23:24 -0700)
committerMax Semenik <maxsem.wiki@gmail.com>
Tue, 5 Jun 2018 06:39:04 +0000 (23:39 -0700)
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

Change-Id: Idcec077ef3fdf029b632cceafd0150851ad723e3

21 files changed:
includes/EditPage.php
includes/GlobalFunctions.php
includes/actions/Action.php
includes/api/ApiBase.php
includes/auth/AuthManager.php
includes/auth/LegacyHookPreAuthenticationProvider.php
includes/cache/CacheDependency.php
includes/cache/CacheHelper.php
includes/changes/CategoryMembershipChange.php
includes/changes/ChangesListBooleanFilter.php
includes/changes/ChangesListStringOptionsFilterGroup.php
includes/context/ContextSource.php
includes/context/DerivativeContext.php
includes/context/RequestContext.php
includes/debug/logger/MonologSpi.php
includes/deferred/AutoCommitUpdate.php
includes/diff/DifferenceEngine.php
includes/filerepo/FileRepo.php
includes/filerepo/ForeignDBRepo.php
includes/filerepo/LocalRepo.php
includes/installer/CliInstaller.php

index 13d1623..22c29d6 100644 (file)
@@ -3541,7 +3541,7 @@ ERROR;
                // Allow for site and per-namespace customization of contribution/copyright notice.
                Hooks::run( 'EditPageCopyrightWarning', [ $title, &$copywarnMsg ] );
 
-               $msg = call_user_func_array( 'wfMessage', $copywarnMsg )->title( $title );
+               $msg = wfMessage( ...$copywarnMsg )->title( $title );
                if ( $langcode ) {
                        $msg->inLanguage( $langcode );
                }
index ae09602..6b4e4ee 100644 (file)
@@ -2196,9 +2196,7 @@ function wfStringToBool( $val ) {
  * @deprecated since 1.30 use MediaWiki\Shell::escape()
  */
 function wfEscapeShellArg( /*...*/ ) {
-       $args = func_get_args();
-
-       return call_user_func_array( Shell::class . '::escape', $args );
+       return Shell::escape( ...func_get_args() );
 }
 
 /**
@@ -2697,10 +2695,7 @@ function wfMakeStaticArrayFile( array $data, $header = 'Automatically generated'
  * @return string
  */
 function wfMemcKey( /*...*/ ) {
-       return call_user_func_array(
-               [ ObjectCache::getLocalClusterInstance(), 'makeKey' ],
-               func_get_args()
-       );
+       return ObjectCache::getLocalClusterInstance()->makeKey( ...func_get_args() );
 }
 
 /**
@@ -2716,10 +2711,7 @@ function wfMemcKey( /*...*/ ) {
 function wfForeignMemcKey( $db, $prefix /*...*/ ) {
        $args = array_slice( func_get_args(), 2 );
        $keyspace = $prefix ? "$db-$prefix" : $db;
-       return call_user_func_array(
-               [ ObjectCache::getLocalClusterInstance(), 'makeKeyInternal' ],
-               [ $keyspace, $args ]
-       );
+       return ObjectCache::getLocalClusterInstance()->makeKeyInternal( $keyspace, $args );
 }
 
 /**
@@ -2735,10 +2727,7 @@ function wfForeignMemcKey( $db, $prefix /*...*/ ) {
  * @return string
  */
 function wfGlobalCacheKey( /*...*/ ) {
-       return call_user_func_array(
-               [ ObjectCache::getLocalClusterInstance(), 'makeGlobalKey' ],
-               func_get_args()
-       );
+       return ObjectCache::getLocalClusterInstance()->makeGlobalKey( ...func_get_args() );
 }
 
 /**
index e8d9a3e..fb22445 100644 (file)
@@ -104,7 +104,7 @@ abstract class Action implements MessageLocalizer {
                }
 
                if ( is_callable( $classOrCallable ) ) {
-                       return call_user_func_array( $classOrCallable, [ $page, $context ] );
+                       return $classOrCallable( $page, $context );
                }
 
                return $classOrCallable;
@@ -255,7 +255,7 @@ abstract class Action implements MessageLocalizer {
         */
        final public function msg( $key ) {
                $params = func_get_args();
-               return call_user_func_array( [ $this->getContext(), 'msg' ], $params );
+               return $this->getContext()->msg( ...$params );
        }
 
        /**
index 8a99e6a..98aa554 100644 (file)
@@ -1819,7 +1819,7 @@ abstract class ApiBase extends ContextSource {
                if ( is_string( $msg ) ) {
                        $msg = wfMessage( $msg );
                } elseif ( is_array( $msg ) ) {
-                       $msg = call_user_func_array( 'wfMessage', $msg );
+                       $msg = wfMessage( ...$msg );
                }
                if ( !$msg instanceof Message ) {
                        return null;
@@ -1866,7 +1866,7 @@ abstract class ApiBase extends ContextSource {
                                        [ 'blockinfo' => ApiQueryUserInfo::getBlockInfo( $user->getBlock() ) ]
                                ) );
                        } else {
-                               call_user_func_array( [ $status, 'fatal' ], (array)$error );
+                               $status->fatal( ...(array)$error );
                        }
                }
                return $status;
@@ -2045,10 +2045,7 @@ abstract class ApiBase extends ContextSource {
                if ( !$status->getErrorsByType( 'error' ) ) {
                        $newStatus = Status::newGood();
                        foreach ( $status->getErrorsByType( 'warning' ) as $err ) {
-                               call_user_func_array(
-                                       [ $newStatus, 'fatal' ],
-                                       array_merge( [ $err['message'] ], $err['params'] )
-                               );
+                               $newStatus->fatal( $err['message'], ...$err['params'] );
                        }
                        if ( !$newStatus->getErrorsByType( 'error' ) ) {
                                $newStatus->fatal( 'unknownerror-nocode' );
@@ -2085,7 +2082,7 @@ abstract class ApiBase extends ContextSource {
                        $user = $this->getUser();
                }
                $rights = (array)$rights;
-               if ( !call_user_func_array( [ $user, 'isAllowedAny' ], $rights ) ) {
+               if ( !$user->isAllowedAny( ...$rights ) ) {
                        $this->dieWithError( [ 'apierror-permissiondenied', $this->msg( "action-{$rights[0]}" ) ] );
                }
        }
index 2adc00e..161dd56 100644 (file)
@@ -240,7 +240,7 @@ class AuthManager implements LoggerAwareInterface {
                global $wgAuth;
 
                if ( $wgAuth && !$wgAuth instanceof AuthManagerAuthPlugin ) {
-                       return call_user_func_array( [ $wgAuth, $method ], $params );
+                       return $wgAuth->$method( ...$params );
                } else {
                        return $return;
                }
@@ -985,7 +985,7 @@ class AuthManager implements LoggerAwareInterface {
                if ( $permErrors ) {
                        $status = Status::newGood();
                        foreach ( $permErrors as $args ) {
-                               call_user_func_array( [ $status, 'fatal' ], $args );
+                               $status->fatal( ...$args );
                        }
                        return $status;
                }
@@ -2427,7 +2427,7 @@ class AuthManager implements LoggerAwareInterface {
                        $providers += $this->getSecondaryAuthenticationProviders();
                }
                foreach ( $providers as $provider ) {
-                       call_user_func_array( [ $provider, $method ], $args );
+                       $provider->$method( ...$args );
                }
        }
 
index 95fe3ab..e8a276c 100644 (file)
@@ -168,7 +168,7 @@ class LegacyHookPreAuthenticationProvider extends AbstractPreAuthenticationProvi
 
                        case LoginForm::USER_MIGRATED:
                                $error = $msg ?: 'login-migrated-generic';
-                               return call_user_func_array( 'StatusValue::newFatal', (array)$error );
+                               return StatusValue::newFatal( ...(array)$error );
 
                        // @codeCoverageIgnoreStart
                        case LoginForm::CREATE_BLOCKED: // Can never happen
index 4ff1004..11df5bc 100644 (file)
@@ -118,7 +118,7 @@ class DependencyWrapper {
                if ( is_object( $obj ) && $obj instanceof DependencyWrapper && !$obj->isExpired() ) {
                        $value = $obj->value;
                } elseif ( $callback ) {
-                       $value = call_user_func_array( $callback, $callbackParams );
+                       $value = $callback( ...$callbackParams );
                        # Cache the newly-generated value
                        $wrapper = new DependencyWrapper( $value, $deps );
                        $wrapper->storeToCache( $cache, $key, $expiry );
index b2a91c2..9db8166 100644 (file)
@@ -294,7 +294,7 @@ class CacheHelper implements ICacheHelper {
                                $args = [ $args ];
                        }
 
-                       $value = call_user_func_array( $computeFunction, $args );
+                       $value = $computeFunction( ...$args );
 
                        if ( $this->cacheEnabled ) {
                                if ( is_null( $key ) ) {
@@ -350,7 +350,7 @@ class CacheHelper implements ICacheHelper {
                        throw new MWException( 'No cache key set, so cannot obtain or save the CacheHelper values.' );
                }
 
-               return call_user_func_array( 'wfMemcKey', $this->cacheKey );
+               return wfMemcKey( ...$this->cacheKey );
        }
 
        /**
index f095b64..a49fb4c 100644 (file)
@@ -187,22 +187,19 @@ class CategoryMembershipChange {
                }
 
                /** @var RecentChange $rc */
-               $rc = call_user_func_array(
-                       $this->newForCategorizationCallback,
-                       [
-                               $timestamp,
-                               $categoryTitle,
-                               $user,
-                               $comment,
-                               $pageTitle,
-                               $lastRevId,
-                               $newRevId,
-                               $lastTimestamp,
-                               $bot,
-                               $ip,
-                               $deleted,
-                               $added
-                       ]
+               $rc = ( $this->newForCategorizationCallback )(
+                       $timestamp,
+                       $categoryTitle,
+                       $user,
+                       $comment,
+                       $pageTitle,
+                       $lastRevId,
+                       $newRevId,
+                       $lastTimestamp,
+                       $bot,
+                       $ip,
+                       $deleted,
+                       $added
                );
                $rc->save();
        }
index f37ed2d..fc37882 100644 (file)
@@ -206,18 +206,15 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                        return;
                }
 
-               call_user_func_array(
-                       $this->queryCallable,
-                       [
-                               get_class( $specialPage ),
-                               $specialPage->getContext(),
-                               $dbr,
-                               &$tables,
-                               &$fields,
-                               &$conds,
-                               &$query_options,
-                               &$join_conds
-                       ]
+               ( $this->queryCallable )(
+                       get_class( $specialPage ),
+                       $specialPage->getContext(),
+                       $dbr,
+                       $tables,
+                       $fields,
+                       $conds,
+                       $query_options,
+                       $join_conds
                );
        }
 
index 8cd7ba8..e06f081 100644 (file)
@@ -200,19 +200,16 @@ class ChangesListStringOptionsFilterGroup extends ChangesListFilterGroup {
 
                sort( $selectedValues );
 
-               call_user_func_array(
-                       $this->queryCallable,
-                       [
-                               get_class( $specialPage ),
-                               $specialPage->getContext(),
-                               $dbr,
-                               &$tables,
-                               &$fields,
-                               &$conds,
-                               &$query_options,
-                               &$join_conds,
-                               $selectedValues
-                       ]
+               ( $this->queryCallable )(
+                       get_class( $specialPage ),
+                       $specialPage->getContext(),
+                       $dbr,
+                       $tables,
+                       $fields,
+                       $conds,
+                       $query_options,
+                       $join_conds,
+                       $selectedValues
                );
        }
 
index 03fb9e2..6182538 100644 (file)
@@ -168,7 +168,7 @@ abstract class ContextSource implements IContextSource {
        public function msg( $key /* $args */ ) {
                $args = func_get_args();
 
-               return call_user_func_array( [ $this->getContext(), 'msg' ], $args );
+               return $this->getContext()->msg( ...$args );
        }
 
        /**
index f7a1815..acf6fcb 100644 (file)
@@ -296,6 +296,6 @@ class DerivativeContext extends ContextSource implements MutableContext {
        public function msg( $key ) {
                $args = func_get_args();
 
-               return call_user_func_array( 'wfMessage', $args )->setContext( $this );
+               return wfMessage( ...$args )->setContext( $this );
        }
 }
index db3a7a9..7563330 100644 (file)
@@ -423,7 +423,7 @@ class RequestContext implements IContextSource, MutableContext {
        public function msg( $key ) {
                $args = func_get_args();
 
-               return call_user_func_array( 'wfMessage', $args )->setContext( $this );
+               return wfMessage( ...$args )->setContext( $this );
        }
 
        /**
index 670ba39..ff653ab 100644 (file)
@@ -199,7 +199,7 @@ class MonologSpi implements Spi {
 
                if ( isset( $spec['calls'] ) ) {
                        foreach ( $spec['calls'] as $method => $margs ) {
-                               call_user_func_array( [ $obj, $method ], $margs );
+                               $obj->$method( ...$margs );
                        }
                }
 
index f9297af..8507157 100644 (file)
@@ -39,7 +39,7 @@ class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback {
                try {
                        /** @var Exception $e */
                        $e = null;
-                       call_user_func_array( $this->callback, [ $this->dbw, $this->fname ] );
+                       ( $this->callback )( $this->dbw, $this->fname );
                } catch ( Exception $e ) {
                }
                if ( $autoTrx ) {
index b1ca435..25ba36a 100644 (file)
@@ -756,10 +756,7 @@ class DifferenceEngine extends ContextSource {
                        // for backwards-compatibility
                        $key = $this->getDiffBodyCacheKey();
                        if ( $key === null ) {
-                               $key = call_user_func_array(
-                                       [ $cache, 'makeKey' ],
-                                       $this->getDiffBodyCacheKeyParams()
-                               );
+                               $key = $cache->makeKey( ...$this->getDiffBodyCacheKeyParams() );
                        }
 
                        // Try cache
index 89bb81a..70068b9 100644 (file)
@@ -1735,7 +1735,7 @@ class FileRepo {
         * @return Status
         */
        public function newFatal( $message /*, parameters...*/ ) {
-               $status = call_user_func_array( [ Status::class, 'newFatal' ], func_get_args() );
+               $status = Status::newFatal( ...func_get_args() );
                $status->cleanCallback = $this->getErrorCleanupFunction();
 
                return $status;
@@ -1840,7 +1840,7 @@ class FileRepo {
                $args = func_get_args();
                array_unshift( $args, 'filerepo', $this->getName() );
 
-               return call_user_func_array( 'wfMemcKey', $args );
+               return wfMemcKey( ...$args );
        }
 
        /**
index 7879448..4b33138 100644 (file)
@@ -132,9 +132,8 @@ class ForeignDBRepo extends LocalRepo {
        function getSharedCacheKey( /*...*/ ) {
                if ( $this->hasSharedCache() ) {
                        $args = func_get_args();
-                       array_unshift( $args, $this->dbName, $this->tablePrefix );
 
-                       return call_user_func_array( 'wfForeignMemcKey', $args );
+                       return wfForeignMemcKey( $this->dbName, $this->tablePrefix, ...$args );
                } else {
                        return false;
                }
index 03a9d44..9a6ef22 100644 (file)
@@ -507,7 +507,7 @@ class LocalRepo extends FileRepo {
        function getSharedCacheKey( /*...*/ ) {
                $args = func_get_args();
 
-               return call_user_func_array( 'wfMemcKey', $args );
+               return wfMemcKey( ...$args );
        }
 
        /**
@@ -590,7 +590,7 @@ class LocalRepo extends FileRepo {
                        wfDebug( __METHOD__ . ": skipped because storage uses sha1 paths\n" );
                        return Status::newGood();
                } else {
-                       return call_user_func_array( 'parent::' . $function, $args );
+                       return parent::$function( ...$args );
                }
        }
 }
index 2264b80..845408a 100644 (file)
@@ -197,7 +197,7 @@ class CliInstaller extends Installer {
 
                if ( count( $warnings ) !== 0 ) {
                        foreach ( $warnings as $w ) {
-                               call_user_func_array( [ $this, 'showMessage' ], $w );
+                               $this->showMessage( ...$w );
                        }
                }