Use PHP 7 '??' operator instead of if-then-else
authorFomafix <fomafix@googlemail.com>
Sat, 20 Oct 2018 21:55:44 +0000 (23:55 +0200)
committerFomafix <fomafix@googlemail.com>
Sun, 21 Oct 2018 19:46:46 +0000 (21:46 +0200)
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb

48 files changed:
includes/api/ApiQueryRevisionsBase.php
includes/api/ApiRollback.php
includes/auth/AuthManagerAuthPlugin.php
includes/cache/localisation/LCStoreCDB.php
includes/cache/localisation/LCStoreStaticArray.php
includes/changes/ChangesListBooleanFilter.php
includes/changes/ChangesListFilterGroup.php
includes/debug/logger/monolog/KafkaHandler.php
includes/htmlform/fields/HTMLMultiSelectField.php
includes/http/MWHttpRequest.php
includes/import/WikiImporter.php
includes/installer/DatabaseUpdater.php
includes/installer/Installer.php
includes/installer/MysqlInstaller.php
includes/installer/WebInstaller.php
includes/installer/WebInstallerExistingWiki.php
includes/installer/WebInstallerOptions.php
includes/jobqueue/JobQueueGroup.php
includes/libs/CSSMin.php
includes/libs/Cookie.php
includes/libs/mime/MimeAnalyzer.php
includes/libs/objectcache/BagOStuff.php
includes/libs/objectcache/RedisBagOStuff.php
includes/libs/rdbms/database/DatabaseMssql.php
includes/libs/rdbms/lbfactory/LBFactoryMulti.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php
includes/logging/LogFormatter.php
includes/logging/LogPage.php
includes/media/IPTC.php
includes/objectcache/ObjectCache.php
includes/parser/DateFormatter.php
includes/parser/ParserOutput.php
includes/parser/Preprocessor_DOM.php
includes/parser/Preprocessor_Hash.php
includes/preferences/DefaultPreferencesFactory.php
includes/registration/ExtensionProcessor.php
includes/resourceloader/ResourceLoader.php
includes/search/SearchEngine.php
includes/shell/Shell.php
includes/site/HashSiteStore.php
includes/skins/BaseTemplate.php
includes/skins/Skin.php
includes/specialpage/SpecialPageFactory.php
includes/specials/formfields/UploadSourceField.php
includes/upload/UploadBase.php
includes/user/User.php
includes/utils/MWFileProps.php
includes/widget/search/InterwikiSearchResultSetWidget.php

index c9f528c..c00010a 100644 (file)
@@ -169,11 +169,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                                        $this->limit = 1;
                                }
                        }
-                       if ( isset( $params['section'] ) ) {
-                               $this->section = $params['section'];
-                       } else {
-                               $this->section = false;
-                       }
+                       $this->section = $params['section'] ?? false;
                }
 
                $userMax = $this->parseContent ? 1 : ( $smallLimit ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
index d2ff790..c9ff260 100644 (file)
@@ -69,10 +69,7 @@ class ApiRollback extends ApiBase {
                        $this->dieStatus( $this->errorArrayToStatus( $retval, $user ) );
                }
 
-               $watch = 'preferences';
-               if ( isset( $params['watchlist'] ) ) {
-                       $watch = $params['watchlist'];
-               }
+               $watch = $params['watchlist'] ?? 'preferences';
 
                // Watch pages
                $this->setWatch( $watch, $titleObj, 'watchrollback' );
index 01d992f..008639c 100644 (file)
@@ -79,11 +79,7 @@ class AuthManagerAuthPlugin extends \AuthPlugin {
        }
 
        public function getDomain() {
-               if ( isset( $this->domain ) ) {
-                       return $this->domain;
-               } else {
-                       return 'invaliddomain';
-               }
+               return $this->domain ?? 'invaliddomain';
        }
 
        public function validDomain( $domain ) {
index 78a4863..246a3dd 100644 (file)
@@ -50,11 +50,7 @@ class LCStoreCDB implements LCStore {
        function __construct( $conf = [] ) {
                global $wgCacheDirectory;
 
-               if ( isset( $conf['directory'] ) ) {
-                       $this->directory = $conf['directory'];
-               } else {
-                       $this->directory = $wgCacheDirectory;
-               }
+               $this->directory = $conf['directory'] ?? $wgCacheDirectory;
        }
 
        public function get( $code, $key ) {
index 3b6da73..c5a2512 100644 (file)
@@ -41,11 +41,7 @@ class LCStoreStaticArray implements LCStore {
        public function __construct( $conf = [] ) {
                global $wgCacheDirectory;
 
-               if ( isset( $conf['directory'] ) ) {
-                       $this->directory = $conf['directory'];
-               } else {
-                       $this->directory = $wgCacheDirectory;
-               }
+               $this->directory = $conf['directory'] ?? $wgCacheDirectory;
        }
 
        public function startWrite( $code ) {
index c781d71..5bb1db9 100644 (file)
@@ -112,11 +112,7 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                        $this->showHide = $filterDefinition['showHide'];
                }
 
-               if ( isset( $filterDefinition['isReplacedInStructuredUi'] ) ) {
-                       $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'];
-               } else {
-                       $this->isReplacedInStructuredUi = false;
-               }
+               $this->isReplacedInStructuredUi = $filterDefinition['isReplacedInStructuredUi'] ?? false;
 
                if ( isset( $filterDefinition['default'] ) ) {
                        $this->setDefault( $filterDefinition['default'] );
@@ -128,11 +124,7 @@ class ChangesListBooleanFilter extends ChangesListFilter {
                        $this->queryCallable = $filterDefinition['queryCallable'];
                }
 
-               if ( isset( $filterDefinition['activeValue'] ) ) {
-                       $this->activeValue = $filterDefinition['activeValue'];
-               } else {
-                       $this->activeValue = true;
-               }
+               $this->activeValue = $filterDefinition['activeValue'] ?? true;
        }
 
        /**
index 9d30537..deec915 100644 (file)
@@ -174,11 +174,7 @@ abstract class ChangesListFilterGroup {
                }
 
                $this->type = $groupDefinition['type'];
-               if ( isset( $groupDefinition['priority'] ) ) {
-                       $this->priority = $groupDefinition['priority'];
-               } else {
-                       $this->priority = self::DEFAULT_PRIORITY;
-               }
+               $this->priority = $groupDefinition['priority'] ?? self::DEFAULT_PRIORITY;
 
                $this->isFullCoverage = $groupDefinition['isFullCoverage'];
 
index 8e71131..ef447d1 100644 (file)
@@ -254,11 +254,7 @@ class KafkaHandler extends AbstractProcessingHandler {
         * @param array $records List of records to append
         */
        protected function addMessages( $channel, array $records ) {
-               if ( isset( $this->options['alias'][$channel] ) ) {
-                       $topic = $this->options['alias'][$channel];
-               } else {
-                       $topic = "monolog_$channel";
-               }
+               $topic = $this->options['alias'][$channel] ?? "monolog_$channel";
                $partition = $this->getRandomPartition( $topic );
                if ( $partition !== null ) {
                        $this->produce->setMessages( $topic, $partition, $records );
index e9ecc40..477cc4c 100644 (file)
@@ -228,11 +228,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable
        }
 
        public function getDefault() {
-               if ( isset( $this->mDefault ) ) {
-                       return $this->mDefault;
-               } else {
-                       return [];
-               }
+               return $this->mDefault ?? [];
        }
 
        public function filterDataForSubmit( $data ) {
index 257955c..435c34d 100644 (file)
@@ -97,11 +97,7 @@ abstract class MWHttpRequest implements LoggerAwareInterface {
                $this->url = wfExpandUrl( $url, PROTO_HTTP );
                $this->parsedUrl = wfParseUrl( $this->url );
 
-               if ( isset( $options['logger'] ) ) {
-                       $this->logger = $options['logger'];
-               } else {
-                       $this->logger = new NullLogger();
-               }
+               $this->logger = $options['logger'] ?? new NullLogger();
 
                if ( !$this->parsedUrl || !Http::isValidURI( $this->url ) ) {
                        $this->status = StatusValue::newFatal( 'http-invalid-url', $url );
index 00a7b52..9098981 100644 (file)
@@ -914,11 +914,7 @@ class WikiImporter {
 
                        $revision->setText( $text );
                }
-               if ( isset( $revisionInfo['timestamp'] ) ) {
-                       $revision->setTimestamp( $revisionInfo['timestamp'] );
-               } else {
-                       $revision->setTimestamp( wfTimestampNow() );
-               }
+               $revision->setTimestamp( $revisionInfo['timestamp'] ?? wfTimestampNow() );
 
                if ( isset( $revisionInfo['comment'] ) ) {
                        $revision->setComment( $revisionInfo['comment'] );
index 0194822..f5d01d6 100644 (file)
@@ -164,10 +164,7 @@ abstract class DatabaseUpdater {
 
                // This will automatically add "AutoloadClasses" to $wgAutoloadClasses
                $data = $registry->readFromQueue( $queue );
-               $hooks = [];
-               if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
-                       $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'];
-               }
+               $hooks = $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ?? [];
                if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
                        $hooks = array_merge_recursive( $hooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] );
                }
index d51ea2e..029f67d 100644 (file)
@@ -537,11 +537,7 @@ abstract class Installer {
         * @return mixed
         */
        public function getVar( $name, $default = null ) {
-               if ( !isset( $this->settings[$name] ) ) {
-                       return $default;
-               } else {
-                       return $this->settings[$name];
-               }
+               return $this->settings[$name] ?? $default;
        }
 
        /**
@@ -1505,9 +1501,8 @@ abstract class Installer {
                $data = $registry->readFromQueue( $queue );
                $wgAutoloadClasses += $data['autoload'];
 
-               $hooksWeWant = isset( $wgHooks['LoadExtensionSchemaUpdates'] ) ?
-                       /** @suppress PhanUndeclaredVariable $wgHooks is set by DefaultSettings */
-                       $wgHooks['LoadExtensionSchemaUpdates'] : [];
+               /** @suppress PhanUndeclaredVariable $wgHooks is set by DefaultSettings */
+               $hooksWeWant = $wgHooks['LoadExtensionSchemaUpdates'] ?? [];
 
                if ( isset( $data['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ) ) {
                        $hooksWeWant = array_merge_recursive(
index 1b0780b..e9a2d03 100644 (file)
@@ -192,11 +192,7 @@ class MysqlInstaller extends DatabaseInstaller {
                                        $existingSchema = false;
                                        $this->parent->showMessage( 'config-unknown-collation' );
                                }
-                               if ( isset( $row->Engine ) ) {
-                                       $existingEngine = $row->Engine;
-                               } else {
-                                       $existingEngine = $row->Type;
-                               }
+                               $existingEngine = $row->Engine ?? $row->Type;
                        }
                } else {
                        $existingSchema = false;
index d8281b0..f555c0f 100644 (file)
@@ -178,17 +178,9 @@ class WebInstaller extends Installer {
                        return $this->session;
                }
 
-               if ( isset( $session['happyPages'] ) ) {
-                       $this->happyPages = $session['happyPages'];
-               } else {
-                       $this->happyPages = [];
-               }
+               $this->happyPages = $session['happyPages'] ?? [];
 
-               if ( isset( $session['skippedPages'] ) ) {
-                       $this->skippedPages = $session['skippedPages'];
-               } else {
-                       $this->skippedPages = [];
-               }
+               $this->skippedPages = $session['skippedPages'] ?? [];
 
                $lowestUnhappy = $this->getLowestUnhappy();
 
@@ -468,11 +460,7 @@ class WebInstaller extends Installer {
         * @return array
         */
        public function getSession( $name, $default = null ) {
-               if ( !isset( $this->session[$name] ) ) {
-                       return $default;
-               } else {
-                       return $this->session[$name];
-               }
+               return $this->session[$name] ?? $default;
        }
 
        /**
@@ -932,11 +920,7 @@ class WebInstaller extends Installer {
                if ( !isset( $params['labelAttribs'] ) ) {
                        $params['labelAttribs'] = [];
                }
-               if ( isset( $params['rawtext'] ) ) {
-                       $labelText = $params['rawtext'];
-               } else {
-                       $labelText = $this->parse( wfMessage( $params['label'] )->text() );
-               }
+               $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->text() );
 
                return "<div class=\"config-input-check\">\n" .
                        $params['help'] .
@@ -978,11 +962,7 @@ class WebInstaller extends Installer {
        public function getRadioSet( $params ) {
                $items = $this->getRadioElements( $params );
 
-               if ( !isset( $params['label'] ) ) {
-                       $label = '';
-               } else {
-                       $label = $params['label'];
-               }
+               $label = $params['label'] ?? '';
 
                if ( !isset( $params['controlName'] ) ) {
                        $params['controlName'] = 'config_' . $params['var'];
index 0c7428f..f25d57c 100644 (file)
@@ -154,16 +154,8 @@ class WebInstallerExistingWiki extends WebInstallerPage {
                        return $status;
                }
 
-               if ( isset( $vars['wgDBadminuser'] ) ) {
-                       $this->setVar( '_InstallUser', $vars['wgDBadminuser'] );
-               } else {
-                       $this->setVar( '_InstallUser', $vars['wgDBuser'] );
-               }
-               if ( isset( $vars['wgDBadminpassword'] ) ) {
-                       $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] );
-               } else {
-                       $this->setVar( '_InstallPassword', $vars['wgDBpassword'] );
-               }
+               $this->setVar( '_InstallUser', $vars['wgDBadminuser'] ?? $vars['wgDBuser'] );
+               $this->setVar( '_InstallPassword', $vars['wgDBadminpassword'] ?? $vars['wgDBpassword'] );
 
                // Test the database connection
                $status = $installer->getConnection();
index 382ed3b..953295a 100644 (file)
@@ -490,11 +490,8 @@ class WebInstallerOptions extends WebInstallerPage {
                        // config-license-cc-0, config-license-pd, config-license-gfdl, config-license-none,
                        // config-license-cc-choose
                        $entry = $this->parent->licenses[$code];
-                       if ( isset( $entry['text'] ) ) {
-                               $this->setVar( 'wgRightsText', $entry['text'] );
-                       } else {
-                               $this->setVar( 'wgRightsText', wfMessage( 'config-license-' . $code )->text() );
-                       }
+                       $this->setVar( 'wgRightsText',
+                               $entry['text'] ?? wfMessage( 'config-license-' . $code )->text() );
                        $this->setVar( 'wgRightsUrl', $entry['url'] );
                        $this->setVar( 'wgRightsIcon', $entry['icon'] );
                } else {
index 820c492..c05feb4 100644 (file)
@@ -105,11 +105,7 @@ class JobQueueGroup {
                global $wgJobTypeConf;
 
                $conf = [ 'wiki' => $this->wiki, 'type' => $type ];
-               if ( isset( $wgJobTypeConf[$type] ) ) {
-                       $conf = $conf + $wgJobTypeConf[$type];
-               } else {
-                       $conf = $conf + $wgJobTypeConf['default'];
-               }
+               $conf += $wgJobTypeConf[$type] ?? $wgJobTypeConf['default'];
                $conf['aggregator'] = JobQueueAggregator::singleton();
                if ( !isset( $conf['readOnlyReason'] ) ) {
                        $conf['readOnlyReason'] = $this->readOnlyReason;
index 92a4f9e..3129c5b 100644 (file)
@@ -202,11 +202,7 @@ class CSSMin {
        public static function getMimeType( $file ) {
                // Infer the MIME-type from the file extension
                $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
-               if ( isset( self::$mimeTypes[$ext] ) ) {
-                       return self::$mimeTypes[$ext];
-               }
-
-               return mime_content_type( realpath( $file ) );
+               return self::$mimeTypes[$ext] ?? mime_content_type( realpath( $file ) );
        }
 
        /**
index c0ab0a0..b7636b1 100644 (file)
@@ -58,11 +58,7 @@ class Cookie {
                        $this->expires = strtotime( $attr['expires'] );
                }
 
-               if ( isset( $attr['path'] ) ) {
-                       $this->path = $attr['path'];
-               } else {
-                       $this->path = '/';
-               }
+               $this->path = $attr['path'] ?? '/';
 
                if ( isset( $attr['domain'] ) ) {
                        if ( self::validateCookieDomain( $attr['domain'] ) ) {
index 77c377b..b93084a 100644 (file)
@@ -753,11 +753,7 @@ EOT;
                $xml = new XmlTypeCheck( $file );
                if ( $xml->wellFormed ) {
                        $xmlTypes = $this->xmlTypes;
-                       if ( isset( $xmlTypes[$xml->getRootElement()] ) ) {
-                               return $xmlTypes[$xml->getRootElement()];
-                       } else {
-                               return 'application/xml';
-                       }
+                       return $xmlTypes[$xml->getRootElement()] ?? 'application/xml';
                }
 
                /**
index 82ae5ae..c6bcc7a 100644 (file)
@@ -112,11 +112,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface {
         * @param array $params
         */
        public function __construct( array $params = [] ) {
-               if ( isset( $params['logger'] ) ) {
-                       $this->setLogger( $params['logger'] );
-               } else {
-                       $this->setLogger( new NullLogger() );
-               }
+               $this->setLogger( $params['logger'] ?? new NullLogger() );
 
                if ( isset( $params['keyspace'] ) ) {
                        $this->keyspace = $params['keyspace'];
index a8047b0..a473210 100644 (file)
@@ -81,11 +81,7 @@ class RedisBagOStuff extends BagOStuff {
                        $this->serverTagMap[is_int( $key ) ? $server : $key] = $server;
                }
 
-               if ( isset( $params['automaticFailover'] ) ) {
-                       $this->automaticFailover = $params['automaticFailover'];
-               } else {
-                       $this->automaticFailover = true;
-               }
+               $this->automaticFailover = $params['automaticFailover'] ?? true;
 
                $this->attrMap[self::ATTR_SYNCWRITES] = self::QOS_SYNCWRITES_NONE;
        }
index 61367f5..de102a7 100644 (file)
@@ -987,10 +987,7 @@ class DatabaseMssql extends Database {
         */
        public function getServerVersion() {
                $server_info = sqlsrv_server_info( $this->conn );
-               $version = 'Error';
-               if ( isset( $server_info['SQLServerVersion'] ) ) {
-                       $version = $server_info['SQLServerVersion'];
-               }
+               $version = $server_info['SQLServerVersion'] ?? 'Error';
 
                return $version;
        }
index 30074ec..cc6824d 100644 (file)
@@ -203,11 +203,7 @@ class LBFactoryMulti extends LBFactory {
                        return $this->lastSection;
                }
                list( $dbName, ) = $this->getDBNameAndPrefix( $domain );
-               if ( isset( $this->sectionsByDB[$dbName] ) ) {
-                       $section = $this->sectionsByDB[$dbName];
-               } else {
-                       $section = 'DEFAULT';
-               }
+               $section = $this->sectionsByDB[$dbName] ?? 'DEFAULT';
                $this->lastSection = $section;
                $this->lastDomain = $domain;
 
@@ -221,11 +217,7 @@ class LBFactoryMulti extends LBFactory {
        public function newMainLB( $domain = false ) {
                list( $dbName, ) = $this->getDBNameAndPrefix( $domain );
                $section = $this->getSectionForDomain( $domain );
-               if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
-                       $groupLoads = $this->groupLoadsByDB[$dbName];
-               } else {
-                       $groupLoads = [];
-               }
+               $groupLoads = $this->groupLoadsByDB[$dbName] ?? [];
 
                if ( isset( $this->groupLoadsBySection[$section] ) ) {
                        $groupLoads = array_merge_recursive(
@@ -370,11 +362,7 @@ class LBFactoryMulti extends LBFactory {
                        if ( isset( $groupLoadsByServer[$serverName] ) ) {
                                $serverInfo['groupLoads'] = $groupLoadsByServer[$serverName];
                        }
-                       if ( isset( $this->hostsByName[$serverName] ) ) {
-                               $serverInfo['host'] = $this->hostsByName[$serverName];
-                       } else {
-                               $serverInfo['host'] = $serverName;
-                       }
+                       $serverInfo['host'] = $this->hostsByName[$serverName] ?? $serverName;
                        $serverInfo['hostName'] = $serverName;
                        $serverInfo['load'] = $load;
                        $serverInfo += [ 'flags' => IDatabase::DBO_DEFAULT ];
index 1f3fe4c..ba40bda 100644 (file)
@@ -204,11 +204,7 @@ class LoadBalancer implements ILoadBalancer {
                        $this->maxLag = $params['maxLag'];
                }
 
-               if ( isset( $params['loadMonitor'] ) ) {
-                       $this->loadMonitorConfig = $params['loadMonitor'];
-               } else {
-                       $this->loadMonitorConfig = [ 'class' => 'LoadMonitorNull' ];
-               }
+               $this->loadMonitorConfig = $params['loadMonitor'] ?? [ 'class' => 'LoadMonitorNull' ];
                $this->loadMonitorConfig += [ 'lagWarnThreshold' => $this->maxLag ];
 
                foreach ( $params['servers'] as $i => $server ) {
@@ -223,22 +219,10 @@ class LoadBalancer implements ILoadBalancer {
                        }
                }
 
-               if ( isset( $params['srvCache'] ) ) {
-                       $this->srvCache = $params['srvCache'];
-               } else {
-                       $this->srvCache = new EmptyBagOStuff();
-               }
-               if ( isset( $params['wanCache'] ) ) {
-                       $this->wanCache = $params['wanCache'];
-               } else {
-                       $this->wanCache = WANObjectCache::newEmpty();
-               }
+               $this->srvCache = $params['srvCache'] ?? new EmptyBagOStuff();
+               $this->wanCache = $params['wanCache'] ?? WANObjectCache::newEmpty();
                $this->profiler = $params['profiler'] ?? null;
-               if ( isset( $params['trxProfiler'] ) ) {
-                       $this->trxProfiler = $params['trxProfiler'];
-               } else {
-                       $this->trxProfiler = new TransactionProfiler();
-               }
+               $this->trxProfiler = $params['trxProfiler'] ?? new TransactionProfiler();
 
                $this->errorLogger = $params['errorLogger'] ?? function ( Exception $e ) {
                        trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING );
@@ -1223,23 +1207,13 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function getServerName( $i ) {
-               if ( isset( $this->servers[$i]['hostName'] ) ) {
-                       $name = $this->servers[$i]['hostName'];
-               } elseif ( isset( $this->servers[$i]['host'] ) ) {
-                       $name = $this->servers[$i]['host'];
-               } else {
-                       $name = '';
-               }
+               $name = $this->servers[$i]['hostName'] ?? $this->servers[$i]['host'] ?? '';
 
                return ( $name != '' ) ? $name : 'localhost';
        }
 
        public function getServerInfo( $i ) {
-               if ( isset( $this->servers[$i] ) ) {
-                       return $this->servers[$i];
-               } else {
-                       return false;
-               }
+               return $this->servers[$i] ?? false;
        }
 
        public function getServerType( $i ) {
index e14c485..b3afe0b 100644 (file)
@@ -51,13 +51,7 @@ class LogFormatter {
                global $wgLogActionsHandlers;
                $fulltype = $entry->getFullType();
                $wildcard = $entry->getType() . '/*';
-               $handler = '';
-
-               if ( isset( $wgLogActionsHandlers[$fulltype] ) ) {
-                       $handler = $wgLogActionsHandlers[$fulltype];
-               } elseif ( isset( $wgLogActionsHandlers[$wildcard] ) ) {
-                       $handler = $wgLogActionsHandlers[$wildcard];
-               }
+               $handler = $wgLogActionsHandlers[$fulltype] ?? $wgLogActionsHandlers[$wildcard] ?? '';
 
                if ( $handler !== '' && is_string( $handler ) && class_exists( $handler ) ) {
                        return new $handler( $entry );
index af99940..b63f818 100644 (file)
@@ -437,11 +437,7 @@ class LogPage {
                global $wgLogNames;
 
                // BC
-               if ( isset( $wgLogNames[$this->type] ) ) {
-                       $key = $wgLogNames[$this->type];
-               } else {
-                       $key = 'log-name-' . $this->type;
-               }
+               $key = $wgLogNames[$this->type] ?? 'log-name-' . $this->type;
 
                return wfMessage( $key );
        }
@@ -454,11 +450,7 @@ class LogPage {
        public function getDescription() {
                global $wgLogHeaders;
                // BC
-               if ( isset( $wgLogHeaders[$this->type] ) ) {
-                       $key = $wgLogHeaders[$this->type];
-               } else {
-                       $key = 'log-description-' . $this->type;
-               }
+               $key = $wgLogHeaders[$this->type] ?? 'log-description-' . $this->type;
 
                return wfMessage( $key );
        }
@@ -470,14 +462,8 @@ class LogPage {
         */
        public function getRestriction() {
                global $wgLogRestrictions;
-               if ( isset( $wgLogRestrictions[$this->type] ) ) {
-                       $restriction = $wgLogRestrictions[$this->type];
-               } else {
-                       // '' always returns true with $user->isAllowed()
-                       $restriction = '';
-               }
-
-               return $restriction;
+               // '' always returns true with $user->isAllowed()
+               return $wgLogRestrictions[$this->type] ?? '';
        }
 
        /**
index 441c515..683ded1 100644 (file)
@@ -222,11 +222,7 @@ class IPTC {
                                case '2#055':
                                        // Date created (not date digitized).
                                        // Maps to exif DateTimeOriginal
-                                       if ( isset( $parsed['2#060'] ) ) {
-                                               $time = $parsed['2#060'];
-                                       } else {
-                                               $time = [];
-                                       }
+                                       $time = $parsed['2#060'] ?? [];
                                        $timestamp = self::timeHelper( $val, $time, $c );
                                        if ( $timestamp ) {
                                                $data['DateTimeOriginal'] = $timestamp;
@@ -236,11 +232,7 @@ class IPTC {
                                case '2#062':
                                        // Date converted to digital representation.
                                        // Maps to exif DateTimeDigitized
-                                       if ( isset( $parsed['2#063'] ) ) {
-                                               $time = $parsed['2#063'];
-                                       } else {
-                                               $time = [];
-                                       }
+                                       $time = $parsed['2#063'] ?? [];
                                        $timestamp = self::timeHelper( $val, $time, $c );
                                        if ( $timestamp ) {
                                                $data['DateTimeDigitized'] = $timestamp;
@@ -249,11 +241,7 @@ class IPTC {
 
                                case '2#030':
                                        // Date released.
-                                       if ( isset( $parsed['2#035'] ) ) {
-                                               $time = $parsed['2#035'];
-                                       } else {
-                                               $time = [];
-                                       }
+                                       $time = $parsed['2#035'] ?? [];
                                        $timestamp = self::timeHelper( $val, $time, $c );
                                        if ( $timestamp ) {
                                                $data['DateTimeReleased'] = $timestamp;
@@ -262,11 +250,7 @@ class IPTC {
 
                                case '2#037':
                                        // Date expires.
-                                       if ( isset( $parsed['2#038'] ) ) {
-                                               $time = $parsed['2#038'];
-                                       } else {
-                                               $time = [];
-                                       }
+                                       $time = $parsed['2#038'] ?? [];
                                        $timestamp = self::timeHelper( $val, $time, $c );
                                        if ( $timestamp ) {
                                                $data['DateTimeExpires'] = $timestamp;
index 6d76d5e..ae42f80 100644 (file)
@@ -169,11 +169,7 @@ class ObjectCache {
         * @throws InvalidArgumentException
         */
        public static function newFromParams( $params ) {
-               if ( isset( $params['loggroup'] ) ) {
-                       $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
-               } else {
-                       $params['logger'] = LoggerFactory::getInstance( 'objectcache' );
-               }
+               $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
                if ( !isset( $params['keyspace'] ) ) {
                        $params['keyspace'] = self::getDefaultKeyspace();
                }
@@ -340,11 +336,7 @@ class ObjectCache {
                        }
                }
                $params['cache'] = self::newFromParams( $params['store'] );
-               if ( isset( $params['loggroup'] ) ) {
-                       $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] );
-               } else {
-                       $params['logger'] = LoggerFactory::getInstance( 'objectcache' );
-               }
+               $params['logger'] = LoggerFactory::getInstance( $params['loggroup'] ?? 'objectcache' );
                if ( !$wgCommandLineMode ) {
                        // Send the statsd data post-send on HTTP requests; avoid in CLI mode (T181385)
                        $params['stats'] = $services->getStatsdDataFactory();
index de02861..fb79442 100644 (file)
@@ -213,10 +213,7 @@ class DateFormatter {
         */
        private function replace( $matches ) {
                # Extract information from $matches
-               $linked = true;
-               if ( isset( $this->mLinked ) ) {
-                       $linked = $this->mLinked;
-               }
+               $linked = $this->mLinked ?? true;
 
                $bits = [];
                $key = $this->keys[$this->mSource];
index 847214a..6260de6 100644 (file)
@@ -1127,11 +1127,7 @@ class ParserOutput extends CacheTime {
         *         or null if no value was set for this key.
         */
        public function getExtensionData( $key ) {
-               if ( isset( $this->mExtensionData[$key] ) ) {
-                       return $this->mExtensionData[$key];
-               }
-
-               return null;
+               return $this->mExtensionData[$key] ?? null;
        }
 
        private static function getTimes( $clock = null ) {
index d00c40f..f4e4efa 100644 (file)
@@ -1876,10 +1876,7 @@ class PPCustomFrame_DOM extends PPFrame_DOM {
         * @return string|bool
         */
        public function getArgument( $index ) {
-               if ( !isset( $this->args[$index] ) ) {
-                       return false;
-               }
-               return $this->args[$index];
+               return $this->args[$index] ?? false;
        }
 
        public function getArguments() {
index 6d6dd89..eb869e2 100644 (file)
@@ -1702,10 +1702,7 @@ class PPCustomFrame_Hash extends PPFrame_Hash {
         * @return string|bool
         */
        public function getArgument( $index ) {
-               if ( !isset( $this->args[$index] ) ) {
-                       return false;
-               }
-               return $this->args[$index];
+               return $this->args[$index] ?? false;
        }
 
        public function getArguments() {
index f32b1b7..47d161c 100644 (file)
@@ -267,11 +267,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                                continue;
                        }
 
-                       if ( isset( $userGroupMemberships[$ueg] ) ) {
-                               $groupStringOrObject = $userGroupMemberships[$ueg];
-                       } else {
-                               $groupStringOrObject = $ueg;
-                       }
+                       $groupStringOrObject = $userGroupMemberships[$ueg] ?? $ueg;
 
                        $userG = UserGroupMembership::getLink( $groupStringOrObject, $context, 'html' );
                        $userM = UserGroupMembership::getLink( $groupStringOrObject, $context, 'html',
index eb56e13..e43b3b8 100644 (file)
@@ -484,11 +484,7 @@ class ExtensionProcessor implements Processor {
         * @param string $dir
         */
        protected function extractConfig2( array $info, $dir ) {
-               if ( isset( $info['config_prefix'] ) ) {
-                       $prefix = $info['config_prefix'];
-               } else {
-                       $prefix = 'wg';
-               }
+               $prefix = $info['config_prefix'] ?? 'wg';
                if ( isset( $info['config'] ) ) {
                        foreach ( $info['config'] as $key => $data ) {
                                $value = $data['value'];
index e2b60fc..981d5d2 100644 (file)
@@ -550,11 +550,7 @@ class ResourceLoader implements LoggerAwareInterface {
                                $object->setConfig( $this->getConfig() );
                                $object->setLogger( $this->logger );
                        } else {
-                               if ( !isset( $info['class'] ) ) {
-                                       $class = ResourceLoaderFileModule::class;
-                               } else {
-                                       $class = $info['class'];
-                               }
+                               $class = $info['class'] ?? ResourceLoaderFileModule::class;
                                /** @var ResourceLoaderModule $object */
                                $object = new $class( $info );
                                $object->setConfig( $this->getConfig() );
index ad9f934..2941f0a 100644 (file)
@@ -219,10 +219,7 @@ abstract class SearchEngine {
         * @return mixed the feature value or null if unset
         */
        public function getFeatureData( $feature ) {
-               if ( isset( $this->features[$feature] ) ) {
-                       return $this->features[$feature];
-               }
-               return null;
+               return $this->features[$feature] ?? null;
        }
 
        /**
index 0ddc443..467e4ef 100644 (file)
@@ -237,7 +237,7 @@ class Shell {
                // Give site config file a chance to run the script in a wrapper.
                // The caller may likely want to call wfBasename() on $script.
                Hooks::run( 'wfShellWikiCmd', [ &$script, &$parameters, &$options ] );
-               $cmd = isset( $options['php'] ) ? [ $options['php'] ] : [ $wgPhpCli ];
+               $cmd = [ $options['php'] ?? $wgPhpCli ];
                if ( isset( $options['wrapper'] ) ) {
                        $cmd[] = $options['wrapper'];
                }
index 6d98e72..f0a6e54 100644 (file)
@@ -87,11 +87,7 @@ class HashSiteStore implements SiteStore {
         * @return Site|null
         */
        public function getSite( $globalId, $source = 'cache' ) {
-               if ( isset( $this->sites[$globalId] ) ) {
-                       return $this->sites[$globalId];
-               } else {
-                       return null;
-               }
+               return $this->sites[$globalId] ?? null;
        }
 
        /**
index 64145ad..a71daa0 100644 (file)
@@ -371,11 +371,7 @@ abstract class BaseTemplate extends QuickTemplate {
         * @return string
         */
        function makeLink( $key, $item, $options = [] ) {
-               if ( isset( $item['text'] ) ) {
-                       $text = $item['text'];
-               } else {
-                       $text = wfMessage( $item['msg'] ?? $key )->text();
-               }
+               $text = $item['text'] ?? wfMessage( $item['msg'] ?? $key )->text();
 
                $html = htmlspecialchars( $text );
 
index 1889167..2c71571 100644 (file)
@@ -342,10 +342,7 @@ abstract class Skin extends ContextSource {
         * @return Title
         */
        public function getRelevantTitle() {
-               if ( isset( $this->mRelevantTitle ) ) {
-                       return $this->mRelevantTitle;
-               }
-               return $this->getTitle();
+               return $this->mRelevantTitle ?? $this->getTitle();
        }
 
        /**
index b91273a..58212dd 100644 (file)
@@ -352,17 +352,11 @@ class SpecialPageFactory {
                $caseFoldedAlias = $this->contLang->caseFold( $bits[0] );
                $caseFoldedAlias = str_replace( ' ', '_', $caseFoldedAlias );
                $aliases = $this->getAliasList();
-               if ( isset( $aliases[$caseFoldedAlias] ) ) {
-                       $name = $aliases[$caseFoldedAlias];
-               } else {
+               if ( !isset( $aliases[$caseFoldedAlias] ) ) {
                        return [ null, null ];
                }
-
-               if ( !isset( $bits[1] ) ) { // T4087
-                       $par = null;
-               } else {
-                       $par = $bits[1];
-               }
+               $name = $aliases[$caseFoldedAlias];
+               $par = $bits[1] ?? null; // T4087
 
                return [ $name, $par ];
        }
@@ -504,11 +498,7 @@ class SpecialPageFactory {
                // @todo FIXME: Redirects broken due to this call
                $bits = explode( '/', $title->getDBkey(), 2 );
                $name = $bits[0];
-               if ( !isset( $bits[1] ) ) { // T4087
-                       $par = null;
-               } else {
-                       $par = $bits[1];
-               }
+               $par = $bits[1] ?? null; // T4087
 
                $page = $this->getPage( $name );
                if ( !$page ) {
index 6dc129c..f53ccea 100644 (file)
@@ -32,13 +32,10 @@ class UploadSourceField extends HTMLTextField {
                $label = Html::rawElement( 'label', [ 'for' => $id ], $this->mLabel );
 
                if ( !empty( $this->mParams['radio'] ) ) {
-                       if ( isset( $this->mParams['radio-id'] ) ) {
-                               $radioId = $this->mParams['radio-id'];
-                       } else {
+                       $radioId = $this->mParams['radio-id'] ??
                                // Old way. For the benefit of extensions that do not define
                                // the 'radio-id' key.
-                               $radioId = 'wpSourceType' . $this->mParams['upload-type'];
-                       }
+                               'wpSourceType' . $this->mParams['upload-type'];
 
                        $attribs = [
                                'name' => 'wpSourceType',
index dcebb60..ea805fb 100644 (file)
@@ -98,11 +98,7 @@ abstract class UploadBase {
                        self::WINDOWS_NONASCII_FILENAME => 'windows-nonascii-filename',
                        self::FILENAME_TOO_LONG => 'filename-toolong',
                ];
-               if ( isset( $code_to_status[$error] ) ) {
-                       return $code_to_status[$error];
-               }
-
-               return 'unknown-error';
+               return $code_to_status[$error] ?? 'unknown-error';
        }
 
        /**
index 5e5ca1b..9c705da 100644 (file)
@@ -1817,11 +1817,7 @@ class User implements IDBAccessObject, UserIdentity {
         */
        public static function getDefaultOption( $opt ) {
                $defOpts = self::getDefaultOptions();
-               if ( isset( $defOpts[$opt] ) ) {
-                       return $defOpts[$opt];
-               } else {
-                       return null;
-               }
+               return $defOpts[$opt] ?? null;
        }
 
        /**
index a20435e..19a3ce5 100644 (file)
@@ -104,11 +104,7 @@ class MWFileProps {
                # NOTE: $gis[2] contains a code for the image type. This is no longer used.
                $info['width'] = $gis[0];
                $info['height'] = $gis[1];
-               if ( isset( $gis['bits'] ) ) {
-                       $info['bits'] = $gis['bits'];
-               } else {
-                       $info['bits'] = 0;
-               }
+               $info['bits'] = $gis['bits'] ?? 0;
 
                return $info;
        }
index 79380de..853601e 100644 (file)
@@ -128,11 +128,8 @@ class InterwikiSearchResultSetWidget implements SearchResultSetWidget {
                $interwiki = $this->iwLookup->fetch( $iwPrefix );
                $parsed = wfParseUrl( wfExpandUrl( $interwiki ? $interwiki->getURL() : '/' ) );
 
-               if ( isset( $this->customCaptions[$iwPrefix] ) ) {
-                       $caption = $this->customCaptions[$iwPrefix];
-               } else {
-                       $caption = $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped();
-               }
+               $caption = $this->customCaptions[$iwPrefix] ??
+                       $this->specialSearch->msg( 'search-interwiki-default', $parsed['host'] )->escaped();
 
                $searchLink = Html::rawElement( 'em', null,
                        Html::rawElement( 'a', [ 'href' => $href, 'target' => '_blank' ], $caption )