Make use of ?? and ?: operators where it makes sense

Change-Id: I1d9d62d80b17d1a05222c6e82f631cb801c311a8
This commit is contained in:
Thiemo Kreuz 2022-04-04 11:57:04 +02:00
parent e6664f55c8
commit e23b070b45
14 changed files with 25 additions and 76 deletions

View file

@ -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'];
}

View file

@ -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 ) {

View file

@ -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'] ) ) {

View file

@ -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'] );

View file

@ -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'];

View file

@ -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'];

View file

@ -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'];

View file

@ -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'];

View file

@ -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();
}

View file

@ -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'] ) ) {

View file

@ -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;
}
/**

View file

@ -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 = [];

View file

@ -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 );

View file

@ -23,11 +23,7 @@ class ExternalStoreForTesting {
$path = explode( '/', $url );
$cluster = $path[2];
$id = $path[3];
if ( isset( $path[4] ) ) {
$itemID = $path[4];
} else {
$itemID = false;
}
$itemID = $path[4] ?? false;
if ( !isset( $this->data[$cluster][$id] ) ) {
return null;