Simplify by using ?: operator

Change-Id: I2851cc51c9e05dd0599733be5af39e19f12b52e2
This commit is contained in:
Fomafix 2019-04-15 10:48:13 +02:00
parent 2368415477
commit 8a314d9b43
7 changed files with 10 additions and 35 deletions

View 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();
}
/**

View 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();
}
/**

View 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() {

View 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();
}

View 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 );
}
/**

View 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();

View 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() {