Merge "Simplify by using ?: operator"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 9 May 2019 16:25:22 +0000 (16:25 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 9 May 2019 16:25:22 +0000 (16:25 +0000)
includes/MagicWord.php
includes/MagicWordArray.php
includes/api/ApiFormatRaw.php
includes/filerepo/file/LocalFileDeleteBatch.php
includes/search/SearchDatabase.php
includes/upload/UploadStash.php
tests/phpunit/includes/MagicWordFactoryTest.php

index 3c77234..0984786 100644 (file)
@@ -109,11 +109,7 @@ class MagicWord {
                $this->mId = $id;
                $this->mSynonyms = (array)$syn;
                $this->mCaseSensitive = $cs;
-               $this->contLang = $contLang;
-
-               if ( !$contLang ) {
-                       $this->contLang = MediaWikiServices::getInstance()->getContentLanguage();
-               }
+               $this->contLang = $contLang ?: MediaWikiServices::getInstance()->getContentLanguage();
        }
 
        /**
index 707c644..73d5173 100644 (file)
@@ -49,10 +49,7 @@ class MagicWordArray {
         */
        public function __construct( $names = [], MagicWordFactory $factory = null ) {
                $this->names = $names;
-               $this->factory = $factory;
-               if ( !$factory ) {
-                       $this->factory = MediaWikiServices::getInstance()->getMagicWordFactory();
-               }
+               $this->factory = $factory ?: MediaWikiServices::getInstance()->getMagicWordFactory();
        }
 
        /**
index 9ec4a2c..1d83f73 100644 (file)
@@ -35,11 +35,8 @@ class ApiFormatRaw extends ApiFormatBase {
         */
        public function __construct( ApiMain $main, ApiFormatBase $errorFallback = null ) {
                parent::__construct( $main, 'raw' );
-               if ( $errorFallback === null ) {
-                       $this->errorFallback = $main->createPrinterByName( $main->getParameter( 'format' ) );
-               } else {
-                       $this->errorFallback = $errorFallback;
-               }
+               $this->errorFallback = $errorFallback ?:
+                       $main->createPrinterByName( $main->getParameter( 'format' ) );
        }
 
        public function getMimeType() {
index ecd63e7..d447945 100644 (file)
@@ -62,12 +62,8 @@ class LocalFileDeleteBatch {
                $this->file = $file;
                $this->reason = $reason;
                $this->suppress = $suppress;
-               if ( $user ) {
-                       $this->user = $user;
-               } else {
-                       global $wgUser;
-                       $this->user = $wgUser;
-               }
+               global $wgUser;
+               $this->user = $user ?: $wgUser;
                $this->status = $file->repo->newGood();
        }
 
index 54bfd28..230cded 100644 (file)
@@ -38,11 +38,7 @@ abstract class SearchDatabase extends SearchEngine {
         * @param IDatabase|null $db The database to search from
         */
        public function __construct( IDatabase $db = null ) {
-               if ( $db ) {
-                       $this->db = $db;
-               } else {
-                       $this->db = wfGetDB( DB_REPLICA );
-               }
+               $this->db = $db ?: wfGetDB( DB_REPLICA );
        }
 
        /**
index 2c4bc11..d39975d 100644 (file)
@@ -89,12 +89,8 @@ class UploadStash {
 
                // if a user was passed, use it. otherwise, attempt to use the global.
                // this keeps FileRepo from breaking when it creates an UploadStash object
-               if ( $user ) {
-                       $this->user = $user;
-               } else {
-                       global $wgUser;
-                       $this->user = $wgUser;
-               }
+               global $wgUser;
+               $this->user = $user ?: $wgUser;
 
                if ( is_object( $this->user ) ) {
                        $this->userId = $this->user->getId();
index 63ca139..065024b 100644 (file)
@@ -7,10 +7,7 @@
  */
 class MagicWordFactoryTest extends MediaWikiTestCase {
        private function makeMagicWordFactory( Language $contLang = null ) {
-               if ( $contLang === null ) {
-                       return new MagicWordFactory( Language::factory( 'en' ) );
-               }
-               return new MagicWordFactory( $contLang );
+               return new MagicWordFactory( $contLang ?: Language::factory( 'en' ) );
        }
 
        public function testGetContentLanguage() {