From 43244db9a2966a33942665b3ba3c624b3b2c1361 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sat, 20 Oct 2018 23:55:44 +0200 Subject: [PATCH] Use PHP 7 '??' operator instead of if-then-else Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb --- includes/api/ApiQueryRevisionsBase.php | 6 +-- includes/api/ApiRollback.php | 5 +-- includes/auth/AuthManagerAuthPlugin.php | 6 +-- includes/cache/localisation/LCStoreCDB.php | 6 +-- .../cache/localisation/LCStoreStaticArray.php | 6 +-- includes/changes/ChangesListBooleanFilter.php | 12 +----- includes/changes/ChangesListFilterGroup.php | 6 +-- .../debug/logger/monolog/KafkaHandler.php | 6 +-- .../htmlform/fields/HTMLMultiSelectField.php | 6 +-- includes/http/MWHttpRequest.php | 6 +-- includes/import/WikiImporter.php | 6 +-- includes/installer/DatabaseUpdater.php | 5 +-- includes/installer/Installer.php | 11 ++---- includes/installer/MysqlInstaller.php | 6 +-- includes/installer/WebInstaller.php | 30 +++------------ .../installer/WebInstallerExistingWiki.php | 12 +----- includes/installer/WebInstallerOptions.php | 7 +--- includes/jobqueue/JobQueueGroup.php | 6 +-- includes/libs/CSSMin.php | 6 +-- includes/libs/Cookie.php | 6 +-- includes/libs/mime/MimeAnalyzer.php | 6 +-- includes/libs/objectcache/BagOStuff.php | 6 +-- includes/libs/objectcache/RedisBagOStuff.php | 6 +-- .../libs/rdbms/database/DatabaseMssql.php | 5 +-- .../libs/rdbms/lbfactory/LBFactoryMulti.php | 18 ++------- .../libs/rdbms/loadbalancer/LoadBalancer.php | 38 +++---------------- includes/logging/LogFormatter.php | 8 +--- includes/logging/LogPage.php | 22 ++--------- includes/media/IPTC.php | 24 ++---------- includes/objectcache/ObjectCache.php | 12 +----- includes/parser/DateFormatter.php | 5 +-- includes/parser/ParserOutput.php | 6 +-- includes/parser/Preprocessor_DOM.php | 5 +-- includes/parser/Preprocessor_Hash.php | 5 +-- .../preferences/DefaultPreferencesFactory.php | 6 +-- includes/registration/ExtensionProcessor.php | 6 +-- includes/resourceloader/ResourceLoader.php | 6 +-- includes/search/SearchEngine.php | 5 +-- includes/shell/Shell.php | 2 +- includes/site/HashSiteStore.php | 6 +-- includes/skins/BaseTemplate.php | 6 +-- includes/skins/Skin.php | 5 +-- includes/specialpage/SpecialPageFactory.php | 18 ++------- .../specials/formfields/UploadSourceField.php | 7 +--- includes/upload/UploadBase.php | 6 +-- includes/user/User.php | 6 +-- includes/utils/MWFileProps.php | 6 +-- .../search/InterwikiSearchResultSetWidget.php | 7 +--- 48 files changed, 76 insertions(+), 342 deletions(-) diff --git a/includes/api/ApiQueryRevisionsBase.php b/includes/api/ApiQueryRevisionsBase.php index c9f528c36f..c00010a131 100644 --- a/includes/api/ApiQueryRevisionsBase.php +++ b/includes/api/ApiQueryRevisionsBase.php @@ -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 ); diff --git a/includes/api/ApiRollback.php b/includes/api/ApiRollback.php index d2ff790296..c9ff260a91 100644 --- a/includes/api/ApiRollback.php +++ b/includes/api/ApiRollback.php @@ -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' ); diff --git a/includes/auth/AuthManagerAuthPlugin.php b/includes/auth/AuthManagerAuthPlugin.php index 01d992fe74..008639c25a 100644 --- a/includes/auth/AuthManagerAuthPlugin.php +++ b/includes/auth/AuthManagerAuthPlugin.php @@ -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 ) { diff --git a/includes/cache/localisation/LCStoreCDB.php b/includes/cache/localisation/LCStoreCDB.php index 78a4863fe7..246a3dda27 100644 --- a/includes/cache/localisation/LCStoreCDB.php +++ b/includes/cache/localisation/LCStoreCDB.php @@ -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 ) { diff --git a/includes/cache/localisation/LCStoreStaticArray.php b/includes/cache/localisation/LCStoreStaticArray.php index 3b6da73944..c5a2512f50 100644 --- a/includes/cache/localisation/LCStoreStaticArray.php +++ b/includes/cache/localisation/LCStoreStaticArray.php @@ -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 ) { diff --git a/includes/changes/ChangesListBooleanFilter.php b/includes/changes/ChangesListBooleanFilter.php index c781d717cc..5bb1db91b7 100644 --- a/includes/changes/ChangesListBooleanFilter.php +++ b/includes/changes/ChangesListBooleanFilter.php @@ -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; } /** diff --git a/includes/changes/ChangesListFilterGroup.php b/includes/changes/ChangesListFilterGroup.php index 9d3053762d..deec915e39 100644 --- a/includes/changes/ChangesListFilterGroup.php +++ b/includes/changes/ChangesListFilterGroup.php @@ -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']; diff --git a/includes/debug/logger/monolog/KafkaHandler.php b/includes/debug/logger/monolog/KafkaHandler.php index 8e7113164a..ef447d150a 100644 --- a/includes/debug/logger/monolog/KafkaHandler.php +++ b/includes/debug/logger/monolog/KafkaHandler.php @@ -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 ); diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index e9ecc40f10..477cc4c1a5 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -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 ) { diff --git a/includes/http/MWHttpRequest.php b/includes/http/MWHttpRequest.php index 257955c13d..435c34db1f 100644 --- a/includes/http/MWHttpRequest.php +++ b/includes/http/MWHttpRequest.php @@ -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 ); diff --git a/includes/import/WikiImporter.php b/includes/import/WikiImporter.php index 00a7b52992..90989812ae 100644 --- a/includes/import/WikiImporter.php +++ b/includes/import/WikiImporter.php @@ -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'] ); diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 019482227e..f5d01d6637 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -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'] ); } diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index d51ea2ed1b..029f67d57a 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -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( diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 1b0780bc8c..e9a2d03e2d 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -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; diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index d8281b015e..f555c0f1b0 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -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 "
\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']; diff --git a/includes/installer/WebInstallerExistingWiki.php b/includes/installer/WebInstallerExistingWiki.php index 0c7428fafc..f25d57ce49 100644 --- a/includes/installer/WebInstallerExistingWiki.php +++ b/includes/installer/WebInstallerExistingWiki.php @@ -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(); diff --git a/includes/installer/WebInstallerOptions.php b/includes/installer/WebInstallerOptions.php index 382ed3bf8d..953295a242 100644 --- a/includes/installer/WebInstallerOptions.php +++ b/includes/installer/WebInstallerOptions.php @@ -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 { diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 820c492e85..c05feb4c00 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -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; diff --git a/includes/libs/CSSMin.php b/includes/libs/CSSMin.php index 92a4f9e6f4..3129c5b21b 100644 --- a/includes/libs/CSSMin.php +++ b/includes/libs/CSSMin.php @@ -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 ) ); } /** diff --git a/includes/libs/Cookie.php b/includes/libs/Cookie.php index c0ab0a0538..b7636b1476 100644 --- a/includes/libs/Cookie.php +++ b/includes/libs/Cookie.php @@ -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'] ) ) { diff --git a/includes/libs/mime/MimeAnalyzer.php b/includes/libs/mime/MimeAnalyzer.php index 77c377b2ca..b93084ad5c 100644 --- a/includes/libs/mime/MimeAnalyzer.php +++ b/includes/libs/mime/MimeAnalyzer.php @@ -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'; } /** diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index 82ae5aea68..c6bcc7a841 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -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']; diff --git a/includes/libs/objectcache/RedisBagOStuff.php b/includes/libs/objectcache/RedisBagOStuff.php index a8047b0c7e..a473210aff 100644 --- a/includes/libs/objectcache/RedisBagOStuff.php +++ b/includes/libs/objectcache/RedisBagOStuff.php @@ -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; } diff --git a/includes/libs/rdbms/database/DatabaseMssql.php b/includes/libs/rdbms/database/DatabaseMssql.php index 61367f5990..de102a74ba 100644 --- a/includes/libs/rdbms/database/DatabaseMssql.php +++ b/includes/libs/rdbms/database/DatabaseMssql.php @@ -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; } diff --git a/includes/libs/rdbms/lbfactory/LBFactoryMulti.php b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php index 30074eca27..cc6824d418 100644 --- a/includes/libs/rdbms/lbfactory/LBFactoryMulti.php +++ b/includes/libs/rdbms/lbfactory/LBFactoryMulti.php @@ -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 ]; diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php b/includes/libs/rdbms/loadbalancer/LoadBalancer.php index 1f3fe4cf54..ba40bda890 100644 --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@ -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 ) { diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index e14c485147..b3afe0bb94 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -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 ); diff --git a/includes/logging/LogPage.php b/includes/logging/LogPage.php index af99940cb1..b63f818155 100644 --- a/includes/logging/LogPage.php +++ b/includes/logging/LogPage.php @@ -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] ?? ''; } /** diff --git a/includes/media/IPTC.php b/includes/media/IPTC.php index 441c515f89..683ded107a 100644 --- a/includes/media/IPTC.php +++ b/includes/media/IPTC.php @@ -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; diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index 6d76d5ed12..ae42f80f17 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -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(); diff --git a/includes/parser/DateFormatter.php b/includes/parser/DateFormatter.php index de02861b3c..fb79442e68 100644 --- a/includes/parser/DateFormatter.php +++ b/includes/parser/DateFormatter.php @@ -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]; diff --git a/includes/parser/ParserOutput.php b/includes/parser/ParserOutput.php index 847214a748..6260de6bc0 100644 --- a/includes/parser/ParserOutput.php +++ b/includes/parser/ParserOutput.php @@ -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 ) { diff --git a/includes/parser/Preprocessor_DOM.php b/includes/parser/Preprocessor_DOM.php index d00c40f6ac..f4e4efa724 100644 --- a/includes/parser/Preprocessor_DOM.php +++ b/includes/parser/Preprocessor_DOM.php @@ -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() { diff --git a/includes/parser/Preprocessor_Hash.php b/includes/parser/Preprocessor_Hash.php index 6d6dd8937b..eb869e21c3 100644 --- a/includes/parser/Preprocessor_Hash.php +++ b/includes/parser/Preprocessor_Hash.php @@ -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() { diff --git a/includes/preferences/DefaultPreferencesFactory.php b/includes/preferences/DefaultPreferencesFactory.php index f32b1b787b..47d161c249 100644 --- a/includes/preferences/DefaultPreferencesFactory.php +++ b/includes/preferences/DefaultPreferencesFactory.php @@ -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', diff --git a/includes/registration/ExtensionProcessor.php b/includes/registration/ExtensionProcessor.php index eb56e1365e..e43b3b88fa 100644 --- a/includes/registration/ExtensionProcessor.php +++ b/includes/registration/ExtensionProcessor.php @@ -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']; diff --git a/includes/resourceloader/ResourceLoader.php b/includes/resourceloader/ResourceLoader.php index e2b60fc672..981d5d2d72 100644 --- a/includes/resourceloader/ResourceLoader.php +++ b/includes/resourceloader/ResourceLoader.php @@ -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() ); diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index ad9f934730..2941f0a96a 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -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; } /** diff --git a/includes/shell/Shell.php b/includes/shell/Shell.php index 0ddc443f31..467e4ef9a9 100644 --- a/includes/shell/Shell.php +++ b/includes/shell/Shell.php @@ -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']; } diff --git a/includes/site/HashSiteStore.php b/includes/site/HashSiteStore.php index 6d98e72530..f0a6e54e39 100644 --- a/includes/site/HashSiteStore.php +++ b/includes/site/HashSiteStore.php @@ -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; } /** diff --git a/includes/skins/BaseTemplate.php b/includes/skins/BaseTemplate.php index 64145adb3a..a71daa0980 100644 --- a/includes/skins/BaseTemplate.php +++ b/includes/skins/BaseTemplate.php @@ -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 ); diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 18891672ec..2c715718fe 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -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(); } /** diff --git a/includes/specialpage/SpecialPageFactory.php b/includes/specialpage/SpecialPageFactory.php index b91273a694..58212dd9d5 100644 --- a/includes/specialpage/SpecialPageFactory.php +++ b/includes/specialpage/SpecialPageFactory.php @@ -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 ) { diff --git a/includes/specials/formfields/UploadSourceField.php b/includes/specials/formfields/UploadSourceField.php index 6dc129c38c..f53cceacaf 100644 --- a/includes/specials/formfields/UploadSourceField.php +++ b/includes/specials/formfields/UploadSourceField.php @@ -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', diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index dcebb60a8d..ea805fb970 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -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'; } /** diff --git a/includes/user/User.php b/includes/user/User.php index 5e5ca1b6f7..9c705da9de 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -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; } /** diff --git a/includes/utils/MWFileProps.php b/includes/utils/MWFileProps.php index a20435e17d..19a3ce5bed 100644 --- a/includes/utils/MWFileProps.php +++ b/includes/utils/MWFileProps.php @@ -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; } diff --git a/includes/widget/search/InterwikiSearchResultSetWidget.php b/includes/widget/search/InterwikiSearchResultSetWidget.php index 79380def75..853601e4cf 100644 --- a/includes/widget/search/InterwikiSearchResultSetWidget.php +++ b/includes/widget/search/InterwikiSearchResultSetWidget.php @@ -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 ) -- 2.20.1