From 8a314d9b43f91dfbcd402ac5e3f03378a4c21226 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Mon, 15 Apr 2019 10:48:13 +0200 Subject: [PATCH] Simplify by using ?: operator Change-Id: I2851cc51c9e05dd0599733be5af39e19f12b52e2 --- includes/MagicWord.php | 6 +----- includes/MagicWordArray.php | 5 +---- includes/api/ApiFormatRaw.php | 7 ++----- includes/filerepo/file/LocalFileDeleteBatch.php | 8 ++------ includes/search/SearchDatabase.php | 6 +----- includes/upload/UploadStash.php | 8 ++------ tests/phpunit/includes/MagicWordFactoryTest.php | 5 +---- 7 files changed, 10 insertions(+), 35 deletions(-) diff --git a/includes/MagicWord.php b/includes/MagicWord.php index 3c77234336..0984786d79 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -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(); } /** diff --git a/includes/MagicWordArray.php b/includes/MagicWordArray.php index 707c644a8d..73d5173d07 100644 --- a/includes/MagicWordArray.php +++ b/includes/MagicWordArray.php @@ -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(); } /** diff --git a/includes/api/ApiFormatRaw.php b/includes/api/ApiFormatRaw.php index 9ec4a2c3fb..1d83f73c87 100644 --- a/includes/api/ApiFormatRaw.php +++ b/includes/api/ApiFormatRaw.php @@ -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() { diff --git a/includes/filerepo/file/LocalFileDeleteBatch.php b/includes/filerepo/file/LocalFileDeleteBatch.php index ecd63e75dd..d447945951 100644 --- a/includes/filerepo/file/LocalFileDeleteBatch.php +++ b/includes/filerepo/file/LocalFileDeleteBatch.php @@ -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(); } diff --git a/includes/search/SearchDatabase.php b/includes/search/SearchDatabase.php index 54bfd28f68..230cdedd71 100644 --- a/includes/search/SearchDatabase.php +++ b/includes/search/SearchDatabase.php @@ -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 ); } /** diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 2c4bc11b71..d39975db1b 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -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(); diff --git a/tests/phpunit/includes/MagicWordFactoryTest.php b/tests/phpunit/includes/MagicWordFactoryTest.php index 63ca1395cf..065024bd73 100644 --- a/tests/phpunit/includes/MagicWordFactoryTest.php +++ b/tests/phpunit/includes/MagicWordFactoryTest.php @@ -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() { -- 2.20.1