From: Fomafix Date: Tue, 12 Jun 2018 20:44:33 +0000 (+0200) Subject: Use PHP 7 '??' operator instead of if-then-else X-Git-Tag: 1.34.0-rc.0~5104 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=0f1858321c37f48d8c01d0d113e99d4441d14594;p=lhc%2Fweb%2Fwiklou.git Use PHP 7 '??' operator instead of if-then-else Change-Id: I790b86e2e9e3e41386144637659516a4bfca1cfe --- diff --git a/includes/AuthPlugin.php b/includes/AuthPlugin.php index b73ecbd8ed..e12db24319 100644 --- a/includes/AuthPlugin.php +++ b/includes/AuthPlugin.php @@ -96,11 +96,7 @@ class AuthPlugin { * @return string */ public function getDomain() { - if ( isset( $this->domain ) ) { - return $this->domain; - } else { - return 'invaliddomain'; - } + return $this->domain ?? 'invaliddomain'; } /** diff --git a/includes/MWNamespace.php b/includes/MWNamespace.php index bfbd557923..73fdd826eb 100644 --- a/includes/MWNamespace.php +++ b/includes/MWNamespace.php @@ -254,11 +254,7 @@ class MWNamespace { */ public static function getCanonicalName( $index ) { $nslist = self::getCanonicalNamespaces(); - if ( isset( $nslist[$index] ) ) { - return $nslist[$index]; - } else { - return false; - } + return $nslist[$index] ?? false; } /** diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 50cc991b70..405be1d2b2 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -755,11 +755,7 @@ class OutputPage extends ContextSource { * @return mixed Property value or null if not found */ public function getProperty( $name ) { - if ( isset( $this->mProperties[$name] ) ) { - return $this->mProperties[$name]; - } else { - return null; - } + return $this->mProperties[$name] ?? null; } /** diff --git a/includes/WebResponse.php b/includes/WebResponse.php index 0208a72ab9..022a49e122 100644 --- a/includes/WebResponse.php +++ b/includes/WebResponse.php @@ -234,10 +234,7 @@ class FauxResponse extends WebResponse { public function getHeader( $key ) { $key = strtoupper( $key ); - if ( isset( $this->headers[$key] ) ) { - return $this->headers[$key]; - } - return null; + return $this->headers[$key] ?? null; } /** @@ -303,10 +300,7 @@ class FauxResponse extends WebResponse { * @return array|null */ public function getCookieData( $name ) { - if ( isset( $this->cookies[$name] ) ) { - return $this->cookies[$name]; - } - return null; + return $this->cookies[$name] ?? null; } /** diff --git a/includes/XmlSelect.php b/includes/XmlSelect.php index 89f2f41cb8..5d7406c64d 100644 --- a/includes/XmlSelect.php +++ b/includes/XmlSelect.php @@ -70,11 +70,7 @@ class XmlSelect { * @return string|null */ public function getAttribute( $name ) { - if ( isset( $this->attributes[$name] ) ) { - return $this->attributes[$name]; - } else { - return null; - } + return $this->attributes[$name] ?? null; } /** diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index dd9e8e194a..90108eb682 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -292,11 +292,7 @@ class LocalisationCache { $this->loadSubitem( $code, $key, $subkey ); } - if ( isset( $this->data[$code][$key][$subkey] ) ) { - return $this->data[$code][$key][$subkey]; - } else { - return null; - } + return $this->data[$code][$key][$subkey] ?? null; } /** @@ -603,11 +599,7 @@ class LocalisationCache { if ( $this->pluralRules === null ) { $this->loadPluralFiles(); } - if ( !isset( $this->pluralRules[$code] ) ) { - return null; - } else { - return $this->pluralRules[$code]; - } + return $this->pluralRules[$code] ?? null; } /** @@ -621,11 +613,7 @@ class LocalisationCache { if ( $this->pluralRuleTypes === null ) { $this->loadPluralFiles(); } - if ( !isset( $this->pluralRuleTypes[$code] ) ) { - return null; - } else { - return $this->pluralRuleTypes[$code]; - } + return $this->pluralRuleTypes[$code] ?? null; } /** @@ -1047,11 +1035,7 @@ class LocalisationCache { } foreach ( $data['preloadedMessages'] as $subkey ) { - if ( isset( $data['messages'][$subkey] ) ) { - $subitem = $data['messages'][$subkey]; - } else { - $subitem = null; - } + $subitem = $data['messages'][$subkey] ?? null; $preload['messages'][$subkey] = $subitem; } diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 60fe85009c..94dcd077a5 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -520,11 +520,7 @@ class RecentChange { continue; } - if ( isset( $this->mExtra['actionCommentIRC'] ) ) { - $actionComment = $this->mExtra['actionCommentIRC']; - } else { - $actionComment = null; - } + $actionComment = $this->mExtra['actionCommentIRC'] ?? null; $feed = RCFeed::factory( $params ); $feed->notify( $this, $actionComment ); diff --git a/includes/collation/IcuCollation.php b/includes/collation/IcuCollation.php index d92c215e11..5f401a588b 100644 --- a/includes/collation/IcuCollation.php +++ b/includes/collation/IcuCollation.php @@ -577,10 +577,6 @@ class IcuCollation extends Collation { '3.4' => '4.1', ]; - if ( isset( $map[$versionPrefix] ) ) { - return $map[$versionPrefix]; - } else { - return false; - } + return $map[$versionPrefix] ?? false; } } diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 70068b998b..3d9a904bf5 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -1177,11 +1177,7 @@ class FileRepo { if ( $status->successCount == 0 ) { $status->setOK( false ); } - if ( isset( $status->value[0] ) ) { - $status->value = $status->value[0]; - } else { - $status->value = false; - } + $status->value = $status->value[0] ?? false; return $status; } diff --git a/includes/filerepo/RepoGroup.php b/includes/filerepo/RepoGroup.php index 89287af0bd..fa4567e0b2 100644 --- a/includes/filerepo/RepoGroup.php +++ b/includes/filerepo/RepoGroup.php @@ -324,11 +324,8 @@ class RepoGroup { } if ( $index === 'local' ) { return $this->localRepo; - } elseif ( isset( $this->foreignRepos[$index] ) ) { - return $this->foreignRepos[$index]; - } else { - return false; } + return $this->foreignRepos[$index] ?? false; } /** diff --git a/includes/htmlform/fields/HTMLCheckMatrix.php b/includes/htmlform/fields/HTMLCheckMatrix.php index df44626a3d..d885c9d2e5 100644 --- a/includes/htmlform/fields/HTMLCheckMatrix.php +++ b/includes/htmlform/fields/HTMLCheckMatrix.php @@ -239,11 +239,7 @@ class HTMLCheckMatrix 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/skins/QuickTemplate.php b/includes/skins/QuickTemplate.php index aa20e202eb..296c133e0b 100644 --- a/includes/skins/QuickTemplate.php +++ b/includes/skins/QuickTemplate.php @@ -77,11 +77,7 @@ abstract class QuickTemplate { * @return mixed The value of the data requested or the deafult */ public function get( $name, $default = null ) { - if ( isset( $this->data[$name] ) ) { - return $this->data[$name]; - } else { - return $default; - } + return $this->data[$name] ?? $default; } /**