Use the ?? feature instead of isset() where it makes sense
authorThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Sun, 24 Mar 2019 21:40:49 +0000 (22:40 +0100)
committerThiemo Kreuz <thiemo.kreuz@wikimedia.de>
Sun, 24 Mar 2019 21:40:49 +0000 (22:40 +0100)
Change-Id: I3a54f36b33d99ef3ff4c63e32e7dfcbcfc296135

includes/ActorMigration.php
includes/MagicWordArray.php
includes/api/ApiFormatBase.php
includes/config/ConfigRepository.php
includes/filerepo/file/ForeignAPIFile.php
includes/media/MediaHandlerFactory.php
tests/parser/ParserTestRunner.php

index 0c33eb9..597b8e7 100644 (file)
@@ -136,11 +136,7 @@ class ActorMigration {
         * @return string[] [ $text, $actor ]
         */
        private static function getFieldNames( $key ) {
-               if ( isset( self::$specialFields[$key] ) ) {
-                       return self::$specialFields[$key];
-               }
-
-               return [ $key . '_text', substr( $key, 0, -5 ) . '_actor' ];
+               return self::$specialFields[$key] ?? [ $key . '_text', substr( $key, 0, -5 ) . '_actor' ];
        }
 
        /**
index fde32ce..707c644 100644 (file)
@@ -268,10 +268,7 @@ class MagicWordArray {
                        return $hash[1][$text];
                }
                $lc = $this->factory->getContentLanguage()->lc( $text );
-               if ( isset( $hash[0][$lc] ) ) {
-                       return $hash[0][$lc];
-               }
-               return false;
+               return $hash[0][$lc] ?? false;
        }
 
        /**
index e033525..bff9fd0 100644 (file)
@@ -158,11 +158,9 @@ abstract class ApiFormatBase extends ApiBase {
 
                if ( !is_array( $paramSettings ) ) {
                        return $paramSettings;
-               } elseif ( isset( $paramSettings[self::PARAM_DFLT] ) ) {
-                       return $paramSettings[self::PARAM_DFLT];
-               } else {
-                       return null;
                }
+
+               return $paramSettings[self::PARAM_DFLT] ?? null;
        }
 
        /**
index 96dc51c..2874c33 100644 (file)
@@ -71,10 +71,8 @@ class ConfigRepository implements SalvageableService {
                if ( !$this->has( $name, true ) ) {
                        throw new \ConfigException( 'The configuration option ' . $name . ' does not exist.' );
                }
-               if ( isset( $this->configItems['public'][$name] ) ) {
-                       return $this->configItems['public'][$name];
-               }
-               return $this->configItems['private'][$name];
+
+               return $this->configItems['public'][$name] ?? $this->configItems['private'][$name];
        }
 
        /**
index c49810c..3a75720 100644 (file)
@@ -184,11 +184,7 @@ class ForeignAPIFile extends File {
         *   null on error
         */
        public function getExtendedMetadata() {
-               if ( isset( $this->mInfo['extmetadata'] ) ) {
-                       return $this->mInfo['extmetadata'];
-               }
-
-               return null;
+               return $this->mInfo['extmetadata'] ?? null;
        }
 
        /**
index 543dc80..82e8d1f 100644 (file)
@@ -66,11 +66,7 @@ class MediaHandlerFactory {
        }
 
        protected function getHandlerClass( $type ) {
-               if ( isset( $this->registry[$type] ) ) {
-                       return $this->registry[$type];
-               } else {
-                       return false;
-               }
+               return $this->registry[$type] ?? false;
        }
 
        /**
index 699de95..1c93261 100644 (file)
@@ -938,12 +938,7 @@ class ParserTestRunner {
         */
        private static function getOptionValue( $key, $opts, $default ) {
                $key = strtolower( $key );
-
-               if ( isset( $opts[$key] ) ) {
-                       return $opts[$key];
-               } else {
-                       return $default;
-               }
+               return $opts[$key] ?? $default;
        }
 
        /**