diff options
author | Thiemo Kreuz <thiemo.kreuz@wikimedia.de> | 2022-04-04 11:57:04 +0200 |
---|---|---|
committer | Thiemo Kreuz <thiemo.kreuz@wikimedia.de> | 2022-08-04 21:43:12 +0200 |
commit | e23b070b4547b6a886519d92dacbb36fbd8511f3 (patch) | |
tree | ef6ab3e15e5b914bf9adba189da31b51f05d0f8f /includes | |
parent | e6664f55c89da5271d751fe6766674006813e686 (diff) | |
download | mediawikicore-e23b070b4547b6a886519d92dacbb36fbd8511f3.tar.gz mediawikicore-e23b070b4547b6a886519d92dacbb36fbd8511f3.zip |
Make use of ?? and ?: operators where it makes sense
Change-Id: I1d9d62d80b17d1a05222c6e82f631cb801c311a8
Diffstat (limited to 'includes')
-rw-r--r-- | includes/LinkFilter.php | 6 | ||||
-rw-r--r-- | includes/api/ApiBase.php | 12 | ||||
-rw-r--r-- | includes/exception/MWExceptionHandler.php | 4 | ||||
-rw-r--r-- | includes/filerepo/FileRepo.php | 9 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLNamespacesMultiselectField.php | 7 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLTagMultiselectField.php | 7 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLTitlesMultiselectField.php | 7 | ||||
-rw-r--r-- | includes/htmlform/fields/HTMLUsersMultiselectField.php | 7 | ||||
-rw-r--r-- | includes/jobqueue/JobQueueGroup.php | 6 | ||||
-rw-r--r-- | includes/parser/Parser.php | 8 | ||||
-rw-r--r-- | includes/parser/Parsoid/Config/PageConfig.php | 9 | ||||
-rw-r--r-- | includes/search/SearchEngineFactory.php | 8 | ||||
-rw-r--r-- | includes/widget/DateTimeInputWidget.php | 5 |
13 files changed, 24 insertions, 71 deletions
diff --git a/includes/LinkFilter.php b/includes/LinkFilter.php index eee2ef4106c3..2b6a56dcb97e 100644 --- a/includes/LinkFilter.php +++ b/includes/LinkFilter.php @@ -204,11 +204,7 @@ class LinkFilter { if ( isset( $bits['port'] ) ) { $index .= ':' . $bits['port']; } - if ( isset( $bits['path'] ) ) { - $index .= $bits['path']; - } else { - $index .= '/'; - } + $index .= $bits['path'] ?? '/'; if ( isset( $bits['query'] ) ) { $index .= '?' . $bits['query']; } diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 90c7e5a94279..9a2bba12996b 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1832,11 +1832,7 @@ abstract class ApiBase extends ContextSource { $settings = []; } - if ( isset( $settings[self::PARAM_HELP_MSG] ) ) { - $msg = $settings[self::PARAM_HELP_MSG]; - } else { - $msg = $this->msg( "apihelp-{$path}-param-{$param}" ); - } + $msg = $settings[self::PARAM_HELP_MSG] ?? $this->msg( "apihelp-$path-param-$param" ); $msg = self::makeMessage( $msg, $this->getContext(), [ $prefix, $param, $name, $path ] ); if ( !$msg ) { @@ -1911,11 +1907,7 @@ abstract class ApiBase extends ContextSource { $deprecatedValues = $settings[EnumDef::PARAM_DEPRECATED_VALUES] ?? []; foreach ( $settings[ParamValidator::PARAM_TYPE] as $value ) { - if ( isset( $valueMsgs[$value] ) ) { - $msg = $valueMsgs[$value]; - } else { - $msg = "apihelp-{$path}-paramvalue-{$param}-{$value}"; - } + $msg = $valueMsgs[$value] ?? "apihelp-$path-paramvalue-$param-$value"; $m = self::makeMessage( $msg, $this->getContext(), [ $prefix, $param, $name, $path, $value ] ); if ( $m ) { diff --git a/includes/exception/MWExceptionHandler.php b/includes/exception/MWExceptionHandler.php index 9391f7dc3efd..4270cbf26003 100644 --- a/includes/exception/MWExceptionHandler.php +++ b/includes/exception/MWExceptionHandler.php @@ -426,10 +426,8 @@ TXT; if ( isset( $frame['class'] ) && isset( $frame['type'] ) && isset( $frame['function'] ) ) { $text .= $frame['class'] . $frame['type'] . $frame['function']; - } elseif ( isset( $frame['function'] ) ) { - $text .= $frame['function']; } else { - $text .= 'NO_FUNCTION_GIVEN'; + $text .= $frame['function'] ?? 'NO_FUNCTION_GIVEN'; } if ( isset( $frame['args'] ) ) { diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 0a0a2b87964a..e77432000795 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -110,7 +110,7 @@ class FileRepo { /** @var string|false Public zone URL. */ protected $url; - /** @var string The base thumbnail URL. Defaults to "<url>/thumb". */ + /** @var string|false The base thumbnail URL. Defaults to "<url>/thumb". */ protected $thumbUrl; /** @var int The number of directory levels for hash-based division of files */ @@ -216,11 +216,8 @@ class FileRepo { } $this->url = $info['url'] ?? false; // a subclass may set the URL (e.g. ForeignAPIRepo) - if ( isset( $info['thumbUrl'] ) ) { - $this->thumbUrl = $info['thumbUrl']; - } else { - $this->thumbUrl = $this->url ? "{$this->url}/thumb" : false; - } + $defaultThumbUrl = $this->url ? $this->url . '/thumb' : false; + $this->thumbUrl = $info['thumbUrl'] ?? $defaultThumbUrl; $this->hashLevels = $info['hashLevels'] ?? 2; $this->deletedHashLevels = $info['deletedHashLevels'] ?? $this->hashLevels; $this->transformVia404 = !empty( $info['transformVia404'] ); diff --git a/includes/htmlform/fields/HTMLNamespacesMultiselectField.php b/includes/htmlform/fields/HTMLNamespacesMultiselectField.php index e17320cb8cbd..b90c25d391ae 100644 --- a/includes/htmlform/fields/HTMLNamespacesMultiselectField.php +++ b/includes/htmlform/fields/HTMLNamespacesMultiselectField.php @@ -81,11 +81,8 @@ class HTMLNamespacesMultiselectField extends HTMLSelectNamespace { $params['default'] = $this->mParams['default']; } - if ( isset( $this->mParams['placeholder'] ) ) { - $params['placeholder'] = $this->mParams['placeholder']; - } else { - $params['placeholder'] = $this->msg( 'mw-widgets-titlesmultiselect-placeholder' )->plain(); - } + $params['placeholder'] = $this->mParams['placeholder'] ?? + $this->msg( 'mw-widgets-titlesmultiselect-placeholder' )->plain(); if ( isset( $this->mParams['max'] ) ) { $params['tagLimit'] = $this->mParams['max']; diff --git a/includes/htmlform/fields/HTMLTagMultiselectField.php b/includes/htmlform/fields/HTMLTagMultiselectField.php index 62e040b60927..c832cbbb51e4 100644 --- a/includes/htmlform/fields/HTMLTagMultiselectField.php +++ b/includes/htmlform/fields/HTMLTagMultiselectField.php @@ -80,11 +80,8 @@ class HTMLTagMultiselectField extends HTMLTextField { $params['default'] = $this->mParams['default']; } - if ( isset( $this->mParams['placeholder'] ) ) { - $params['placeholder'] = $this->mParams['placeholder']; - } else { - $params['placeholder'] = $this->msg( 'mw-widgets-tagmultiselect-placeholder' )->plain(); - } + $params['placeholder'] = $this->mParams['placeholder'] ?? + $this->msg( 'mw-widgets-tagmultiselect-placeholder' )->plain(); if ( isset( $this->mParams['max'] ) ) { $params['tagLimit'] = $this->mParams['max']; diff --git a/includes/htmlform/fields/HTMLTitlesMultiselectField.php b/includes/htmlform/fields/HTMLTitlesMultiselectField.php index 5f41bb137423..c21d129c77a6 100644 --- a/includes/htmlform/fields/HTMLTitlesMultiselectField.php +++ b/includes/htmlform/fields/HTMLTitlesMultiselectField.php @@ -92,11 +92,8 @@ class HTMLTitlesMultiselectField extends HTMLTitleTextField { $params['default'] = $this->mParams['default']; } - if ( isset( $this->mParams['placeholder'] ) ) { - $params['placeholder'] = $this->mParams['placeholder']; - } else { - $params['placeholder'] = $this->msg( 'mw-widgets-titlesmultiselect-placeholder' )->plain(); - } + $params['placeholder'] = $this->mParams['placeholder'] ?? + $this->msg( 'mw-widgets-titlesmultiselect-placeholder' )->plain(); if ( isset( $this->mParams['max'] ) ) { $params['tagLimit'] = $this->mParams['max']; diff --git a/includes/htmlform/fields/HTMLUsersMultiselectField.php b/includes/htmlform/fields/HTMLUsersMultiselectField.php index acdae75f7b32..3fa0ab0a9665 100644 --- a/includes/htmlform/fields/HTMLUsersMultiselectField.php +++ b/includes/htmlform/fields/HTMLUsersMultiselectField.php @@ -101,11 +101,8 @@ class HTMLUsersMultiselectField extends HTMLUserTextField { $params['default'] = $this->mParams['default']; } - if ( isset( $this->mParams['placeholder'] ) ) { - $params['placeholder'] = $this->mParams['placeholder']; - } else { - $params['placeholder'] = $this->msg( 'mw-widgets-usersmultiselect-placeholder' )->plain(); - } + $params['placeholder'] = $this->mParams['placeholder'] ?? + $this->msg( 'mw-widgets-usersmultiselect-placeholder' )->plain(); if ( isset( $this->mParams['max'] ) ) { $params['tagLimit'] = $this->mParams['max']; diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 110a1c1be646..8eec6ef25638 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -134,11 +134,7 @@ class JobQueueGroup { */ public function get( $type ) { $conf = [ 'domain' => $this->domain, 'type' => $type ]; - if ( isset( $this->jobTypeConfiguration[$type] ) ) { - $conf += $this->jobTypeConfiguration[$type]; - } else { - $conf += $this->jobTypeConfiguration['default']; - } + $conf += $this->jobTypeConfiguration[$type] ?? $this->jobTypeConfiguration['default']; if ( !isset( $conf['readOnlyReason'] ) ) { $conf['readOnlyReason'] = $this->readOnlyMode->getReason(); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 6d282c72b1e1..b6455205341e 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3617,12 +3617,8 @@ class Parser { // Defaults to Parser::statelessFetchTemplate() $templateCb = $this->mOptions->getTemplateCallback(); - $stuff = call_user_func( $templateCb, $title, $this ); - if ( isset( $stuff['revision-record'] ) ) { - $revRecord = $stuff['revision-record']; - } else { - $revRecord = null; - } + $stuff = $templateCb( $title, $this ); + $revRecord = $stuff['revision-record'] ?? null; $text = $stuff['text']; if ( is_string( $stuff['text'] ) ) { diff --git a/includes/parser/Parsoid/Config/PageConfig.php b/includes/parser/Parsoid/Config/PageConfig.php index 91cfb87de8da..7946fa70806b 100644 --- a/includes/parser/Parsoid/Config/PageConfig.php +++ b/includes/parser/Parsoid/Config/PageConfig.php @@ -167,13 +167,8 @@ class PageConfig extends IPageConfig { // (Parsoid will track dependencies, etc, itself.) // The callback defaults to Parser::statelessFetchTemplate() $templateCb = $this->parserOptions->getTemplateCallback(); - $stuff = call_user_func( $templateCb, $title, $this ); - if ( isset( $stuff['revision-record'] ) ) { - $revRecord = $stuff['revision-record']; - } else { - $revRecord = null; - } - return $revRecord; + $stuff = $templateCb( $title, $this ); + return $stuff['revision-record'] ?? null; } /** diff --git a/includes/search/SearchEngineFactory.php b/includes/search/SearchEngineFactory.php index 5adde575ed7d..7c3e7231d866 100644 --- a/includes/search/SearchEngineFactory.php +++ b/includes/search/SearchEngineFactory.php @@ -57,12 +57,8 @@ class SearchEngineFactory { $mappings = $this->config->getSearchMappings(); - if ( isset( $mappings[$class] ) ) { - $spec = $mappings[$class]; - } else { - // Convert non mapped classes to ObjectFactory spec - $spec = [ 'class' => $class ]; - } + // Convert non mapped classes to ObjectFactory spec + $spec = $mappings[$class] ?? [ 'class' => $class ]; $args = []; diff --git a/includes/widget/DateTimeInputWidget.php b/includes/widget/DateTimeInputWidget.php index 21e3d7930daf..d11e1e25f16e 100644 --- a/includes/widget/DateTimeInputWidget.php +++ b/includes/widget/DateTimeInputWidget.php @@ -26,11 +26,10 @@ class DateTimeInputWidget extends \OOUI\InputWidget { */ public function __construct( array $config = [] ) { // We need $this->type set before calling the parent constructor - if ( isset( $config['type'] ) ) { - $this->type = $config['type']; - } else { + if ( !isset( $config['type'] ) ) { throw new \InvalidArgumentException( '$config[\'type\'] must be specified' ); } + $this->type = $config['type']; parent::__construct( $config ); |