Use PHP 7 '??' operator instead of if-then-else
authorFomafix <fomafix@googlemail.com>
Tue, 12 Jun 2018 20:44:33 +0000 (22:44 +0200)
committerFomafix <fomafix@googlemail.com>
Tue, 12 Jun 2018 21:14:18 +0000 (23:14 +0200)
Change-Id: I790b86e2e9e3e41386144637659516a4bfca1cfe

12 files changed:
includes/AuthPlugin.php
includes/MWNamespace.php
includes/OutputPage.php
includes/WebResponse.php
includes/XmlSelect.php
includes/cache/localisation/LocalisationCache.php
includes/changes/RecentChange.php
includes/collation/IcuCollation.php
includes/filerepo/FileRepo.php
includes/filerepo/RepoGroup.php
includes/htmlform/fields/HTMLCheckMatrix.php
includes/skins/QuickTemplate.php

index b73ecbd..e12db24 100644 (file)
@@ -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';
        }
 
        /**
index bfbd557..73fdd82 100644 (file)
@@ -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;
        }
 
        /**
index 50cc991..405be1d 100644 (file)
@@ -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;
        }
 
        /**
index 0208a72..022a49e 100644 (file)
@@ -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;
        }
 
        /**
index 89f2f41..5d7406c 100644 (file)
@@ -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;
        }
 
        /**
index dd9e8e1..90108eb 100644 (file)
@@ -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;
                }
 
index 60fe850..94dcd07 100644 (file)
@@ -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 );
index d92c215..5f401a5 100644 (file)
@@ -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;
        }
 }
index 70068b9..3d9a904 100644 (file)
@@ -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;
        }
index 89287af..fa4567e 100644 (file)
@@ -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;
        }
 
        /**
index df44626..d885c9d 100644 (file)
@@ -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 ) {
index aa20e20..296c133 100644 (file)
@@ -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;
        }
 
        /**