From 3a66680ec587e131a288f01ac75cf6242bc406d7 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Fri, 17 May 2019 16:54:47 +0200 Subject: [PATCH] Simplify a few list() that only care about the first element The nice thing about explode() is that the resulting array is guaranteed to contain at least one element. The array can not be empty. In some of these cases it might be possible to use strstr() instead, but that returns an empty string when the needle character is not found. explode() returns the original string in this case. Change-Id: I6ad1f3273defeaf36e2305fd871eaaf9d3c1e134 --- includes/OutputHandler.php | 2 +- includes/installer/Installer.php | 2 +- includes/media/FormatMetadata.php | 2 +- includes/specials/SpecialRedirect.php | 4 ++-- includes/specials/pagers/UsersPager.php | 4 ++-- maintenance/update.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/OutputHandler.php b/includes/OutputHandler.php index 16c37841c8..ba9e2d7a2c 100644 --- a/includes/OutputHandler.php +++ b/includes/OutputHandler.php @@ -62,7 +62,7 @@ class OutputHandler { /// @todo FIXME: this sort of dupes some code in WebRequest::getRequestUrl() if ( isset( $_SERVER['REQUEST_URI'] ) ) { // Strip the query string... - list( $path ) = explode( '?', $_SERVER['REQUEST_URI'], 2 ); + $path = explode( '?', $_SERVER['REQUEST_URI'], 2 )[0]; } elseif ( isset( $_SERVER['SCRIPT_NAME'] ) ) { // Probably IIS. QUERY_STRING appears separately. $path = $_SERVER['SCRIPT_NAME']; diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 5c3d1d0b86..26f9bf0d3d 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -494,7 +494,7 @@ abstract class Installer { $good = true; // Must go here because an old version of PCRE can prevent other checks from completing - list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 ); + $pcreVersion = explode( ' ', PCRE_VERSION, 2 )[0]; if ( version_compare( $pcreVersion, self::MINIMUM_PCRE_VERSION, '<' ) ) { $this->showError( 'config-pcre-old', self::MINIMUM_PCRE_VERSION, $pcreVersion ); $good = false; diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index 345b3cb60f..333c610375 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -1181,7 +1181,7 @@ class FormatMetadata extends ContextSource { $langName = Language::fetchLanguageName( $lowLang ); if ( $langName === '' ) { // try just the base language name. (aka en-US -> en ). - list( $langPrefix ) = explode( '-', $lowLang, 2 ); + $langPrefix = explode( '-', $lowLang, 2 )[0]; $langName = Language::fetchLanguageName( $langPrefix ); if ( $langName === '' ) { // give up. diff --git a/includes/specials/SpecialRedirect.php b/includes/specials/SpecialRedirect.php index c4e4635ab5..49f1b3cd6a 100644 --- a/includes/specials/SpecialRedirect.php +++ b/includes/specials/SpecialRedirect.php @@ -61,8 +61,8 @@ class SpecialRedirect extends FormSpecialPage { function setParameter( $subpage ) { // parse $subpage to pull out the parts $parts = explode( '/', $subpage, 2 ); - $this->mType = count( $parts ) > 0 ? $parts[0] : null; - $this->mValue = count( $parts ) > 1 ? $parts[1] : null; + $this->mType = $parts[0]; + $this->mValue = $parts[1] ?? null; } /** diff --git a/includes/specials/pagers/UsersPager.php b/includes/specials/pagers/UsersPager.php index 4453772fb2..57b575b8ec 100644 --- a/includes/specials/pagers/UsersPager.php +++ b/includes/specials/pagers/UsersPager.php @@ -49,7 +49,7 @@ class UsersPager extends AlphabeticPager { } $request = $this->getRequest(); - $par = ( $par !== null ) ? $par : ''; + $par = $par ?? ''; $parms = explode( '/', $par ); $symsForAll = [ '*', 'user' ]; @@ -277,7 +277,7 @@ class UsersPager extends AlphabeticPager { * @return string */ function getPageHeader() { - list( $self ) = explode( '/', $this->getTitle()->getPrefixedDBkey() ); + $self = explode( '/', $this->getTitle()->getPrefixedDBkey(), 2 )[0]; $groupOptions = [ $this->msg( 'group-all' )->text() => '' ]; foreach ( $this->getAllGroups() as $group => $groupText ) { diff --git a/maintenance/update.php b/maintenance/update.php index 50fb6dc503..b6c7ae473b 100755 --- a/maintenance/update.php +++ b/maintenance/update.php @@ -64,7 +64,7 @@ class UpdateMediaWiki extends Maintenance { function compatChecks() { $minimumPcreVersion = Installer::MINIMUM_PCRE_VERSION; - list( $pcreVersion ) = explode( ' ', PCRE_VERSION, 2 ); + $pcreVersion = explode( ' ', PCRE_VERSION, 2 )[0]; if ( version_compare( $pcreVersion, $minimumPcreVersion, '<' ) ) { $this->fatalError( "PCRE $minimumPcreVersion or later is required.\n" . -- 2.20.1