Make use of ??=, ?: and similar operators where possible

The main benefit of these operators is that they avoid repeating
parts of the code.

Change-Id: I86ea0eb02715ad5b7c62a71849309ed7095c5972
This commit is contained in:
thiemowmde 2024-08-26 17:33:39 +02:00 committed by jenkins-bot
parent b1cc0225a9
commit a630e3d129
4 changed files with 6 additions and 14 deletions

View file

@ -228,9 +228,9 @@ class SiteLibrary extends LibraryBase {
$val = [
'prefix' => $prefix,
'url' => $urlUtils->expand( $row['iw_url'], PROTO_RELATIVE ) ?? false,
'isProtocolRelative' => substr( $row['iw_url'], 0, 2 ) === '//',
'isLocal' => isset( $row['iw_local'] ) && $row['iw_local'] == '1',
'isTranscludable' => isset( $row['iw_trans'] ) && $row['iw_trans'] == '1',
'isProtocolRelative' => str_starts_with( $row['iw_url'], '//' ),
'isLocal' => (bool)( $row['iw_local'] ?? false ),
'isTranscludable' => (bool)( $row['iw_trans'] ?? false ),
'isCurrentWiki' => in_array( $prefix, $localInterwikis ),
'isExtraLanguageLink' => in_array( $prefix, $extraInterlanguageLinkPrefixes ),
];

View file

@ -106,9 +106,7 @@ foreach ( $pats as $k => $pp ) {
$rstart = null;
foreach ( $chars as $i => $c ) {
if ( preg_match( "/^$re$/u", $c ) && !preg_match( "/^$re2$/u", $c ) ) {
if ( $rstart === null ) {
$rstart = $i;
}
$rstart ??= $i;
} elseif ( $rstart !== null ) {
addRange( $k, $rstart, $i );
$rstart = null;

View file

@ -103,10 +103,7 @@ abstract class LuaEngineTestBase extends MediaWikiLangTestCase {
public function toString(): string {
// When running tests written in Lua, return a nicer representation in
// the failure message.
if ( $this->luaTestName ) {
return $this->engineName . ': ' . $this->luaTestName;
}
return $this->engineName . ': ' . parent::toString();
return $this->engineName . ': ' . ( $this->luaTestName ?: parent::toString() );
}
/**

View file

@ -91,10 +91,7 @@ abstract class LuaEngineUnitTestBase extends TestCase {
public function toString(): string {
// When running tests written in Lua, return a nicer representation in
// the failure message.
if ( $this->luaTestName ) {
return $this->engineName . ': ' . $this->luaTestName;
}
return $this->engineName . ': ' . parent::toString();
return $this->engineName . ': ' . ( $this->luaTestName ?: parent::toString() );
}
/**