aboutsummaryrefslogtreecommitdiffstats
path: root/includes/site
diff options
context:
space:
mode:
authorthiemowmde <thiemo.kreuz@wikimedia.de>2024-07-18 15:38:01 +0200
committerthiemowmde <thiemo.kreuz@wikimedia.de>2024-07-18 15:38:01 +0200
commit1356804aff20a70e22fcd0ce95fa8e5705da9507 (patch)
treed3dfb7a5e73a451c91e79eb6f519d68b9546d339 /includes/site
parent5d9062553100a3d56993c8b0b496a087b9dbee52 (diff)
downloadmediawikicore-1356804aff20a70e22fcd0ce95fa8e5705da9507.tar.gz
mediawikicore-1356804aff20a70e22fcd0ce95fa8e5705da9507.zip
site: Streamline Site class using modern PHP features
I believe this makes such code much easier to read and less error-prone. Change-Id: I40023b28b934bc75d1217d23ad6ec181312db11e
Diffstat (limited to 'includes/site')
-rw-r--r--includes/site/Site.php22
1 files changed, 6 insertions, 16 deletions
diff --git a/includes/site/Site.php b/includes/site/Site.php
index b70bcb804f70..bf6925c4563a 100644
--- a/includes/site/Site.php
+++ b/includes/site/Site.php
@@ -278,13 +278,8 @@ class Site {
throw new UnexpectedValueException( "failed to parse URL '$path'" );
}
- // No schema
- if ( $protocol === null ) {
- // Used for protocol relative URLs
- $protocol = '';
- }
-
- return $protocol;
+ // Used for protocol relative URLs
+ return $protocol ?? '';
}
/**
@@ -489,9 +484,7 @@ class Site {
$this->localIds = [];
}
- if ( !array_key_exists( $type, $this->localIds ) ) {
- $this->localIds[$type] = [];
- }
+ $this->localIds[$type] ??= [];
if ( !in_array( $identifier, $this->localIds[$type] ) ) {
$this->localIds[$type][] = $identifier;
@@ -528,9 +521,7 @@ class Site {
* @return string[]
*/
public function getInterwikiIds() {
- return array_key_exists( self::ID_INTERWIKI, $this->localIds )
- ? $this->localIds[self::ID_INTERWIKI]
- : [];
+ return $this->localIds[self::ID_INTERWIKI] ?? [];
}
/**
@@ -542,9 +533,7 @@ class Site {
* @return string[]
*/
public function getNavigationIds() {
- return array_key_exists( self::ID_EQUIVALENT, $this->localIds )
- ? $this->localIds[self::ID_EQUIVALENT] :
- [];
+ return $this->localIds[self::ID_EQUIVALENT] ?? [];
}
/**
@@ -618,6 +607,7 @@ class Site {
* @return Site
*/
public static function newForType( $siteType ) {
+ /** @var class-string<Site>[] $siteTypes */
$siteTypes = MediaWikiServices::getInstance()->getMainConfig()->get(
MainConfigNames::SiteTypes
);