From: Thiemo Kreuz Date: Sun, 24 Mar 2019 14:04:32 +0000 (+0100) Subject: Make use of the list() feature where it makes sense X-Git-Tag: 1.34.0-rc.0~2390 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=9314453c93e9daa502a706063b66d003adcbee0b;p=lhc%2Fweb%2Fwiklou.git Make use of the list() feature where it makes sense This code is functionally identical, but less error prone (not so easy to forget or mix these numerical indexes). This patch happens to touch the Parser, which might be a bit scary. We can remove this file from this patch if you prefer. Change-Id: I8cbe3a9a6725d1c42b86e67678c1af15fbc5961a --- diff --git a/includes/Linker.php b/includes/Linker.php index 5e07f1e1de..decc13cb41 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1710,12 +1710,8 @@ class Linker { static function splitTrail( $trail ) { $regex = MediaWikiServices::getInstance()->getContentLanguage()->linkTrail(); $inside = ''; - if ( $trail !== '' ) { - $m = []; - if ( preg_match( $regex, $trail, $m ) ) { - $inside = $m[1]; - $trail = $m[2]; - } + if ( $trail !== '' && preg_match( $regex, $trail, $m ) ) { + list( , $inside, $trail ) = $m; } return [ $inside, $trail ]; } diff --git a/includes/cache/localisation/LCStoreStaticArray.php b/includes/cache/localisation/LCStoreStaticArray.php index 75c8465abf..f860146804 100644 --- a/includes/cache/localisation/LCStoreStaticArray.php +++ b/includes/cache/localisation/LCStoreStaticArray.php @@ -101,8 +101,7 @@ class LCStoreStaticArray implements LCStore { return $encoded; } - $type = $encoded[0]; - $data = $encoded[1]; + list( $type, $data ) = $encoded; switch ( $type ) { case 'a': diff --git a/includes/diff/DiffEngine.php b/includes/diff/DiffEngine.php index edf844417e..546a12cb79 100644 --- a/includes/diff/DiffEngine.php +++ b/includes/diff/DiffEngine.php @@ -456,9 +456,7 @@ class DiffEngine { // need to store these so we don't lose them when they're // overwritten by the recursion - $len = $snake[2]; - $startx = $snake[0]; - $starty = $snake[1]; + list( $startx, $starty, $len ) = $snake; // the middle snake is part of the LCS, store it for ( $i = 0; $i < $len; ++$i ) { diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 5ede631aa3..9de7eb8408 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -72,11 +72,9 @@ class TraditionalImageGallery extends ImageGalleryBase { $lang = $this->getRenderLang(); # Output each image... foreach ( $this->mImages as $pair ) { + // "text" means "caption" here /** @var Title $nt */ - $nt = $pair[0]; - $text = $pair[1]; # "text" means "caption" here - $alt = $pair[2]; - $link = $pair[3]; + list( $nt, $text, $alt, $link ) = $pair; $descQuery = false; if ( $nt->getNamespace() === NS_FILE ) { diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index 7a92807e0c..750f10870a 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -410,9 +410,7 @@ abstract class DatabaseUpdater { $this->updatesSkipped = []; foreach ( $updates as $funcList ) { - $func = $funcList[0]; - $args = $funcList[1]; - $origParams = $funcList[2]; + list( $func, $args, $origParams ) = $funcList; $func( ...$args ); flush(); $this->updatesSkipped[] = $origParams; diff --git a/includes/libs/rdbms/database/DatabaseMysqli.php b/includes/libs/rdbms/database/DatabaseMysqli.php index 1c4ed56d40..15eeccf02c 100644 --- a/includes/libs/rdbms/database/DatabaseMysqli.php +++ b/includes/libs/rdbms/database/DatabaseMysqli.php @@ -78,9 +78,7 @@ class DatabaseMysqli extends DatabaseMysqlBase { } elseif ( substr_count( $realServer, ':' ) == 1 ) { // If we have a colon and something that's not a port number // inside the hostname, assume it's the socket location - $hostAndSocket = explode( ':', $realServer, 2 ); - $realServer = $hostAndSocket[0]; - $socket = $hostAndSocket[1]; + list( $realServer, $socket ) = explode( ':', $realServer, 2 ); } $mysqli = mysqli_init(); diff --git a/includes/page/ImagePage.php b/includes/page/ImagePage.php index 66804bc152..60237ff1ab 100644 --- a/includes/page/ImagePage.php +++ b/includes/page/ImagePage.php @@ -321,9 +321,7 @@ class ImagePage extends Article { $dirmark = $lang->getDirMarkEntity(); $request = $this->getContext()->getRequest(); - $max = $this->getImageLimitsFromOption( $user, 'imagesize' ); - $maxWidth = $max[0]; - $maxHeight = $max[1]; + list( $maxWidth, $maxHeight ) = $this->getImageLimitsFromOption( $user, 'imagesize' ); if ( $this->displayImg->exists() ) { # image @@ -1029,7 +1027,7 @@ EOT * * @param User $user * @param string $optionName Name of a option to check, typically imagesize or thumbsize - * @return array + * @return int[] * @since 1.21 */ public function getImageLimitsFromOption( $user, $optionName ) { diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 078c819d6f..64164490c2 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -632,8 +632,7 @@ class LinkHolderArray { * @private */ public function replaceTextCallback( $matches ) { - $type = $matches[1]; - $key = $matches[2]; + list( , $type, $key ) = $matches; if ( $type == 'LINK' ) { list( $ns, $index ) = explode( ':', $key, 2 ); if ( isset( $this->internals[$ns][$index]['text'] ) ) { diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 546152f6c9..0440e89408 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -1045,10 +1045,7 @@ class Parser { $inside = $p[5]; } else { # tag - $element = $p[1]; - $attributes = $p[2]; - $close = $p[3]; - $inside = $p[4]; + list( , $element, $attributes, $close, $inside ) = $p; } $marker = self::MARKER_PREFIX . "-$element-" . sprintf( '%08X', $n++ ) . self::MARKER_SUFFIX; @@ -1072,8 +1069,7 @@ class Parser { $tail = ''; $text = ''; } else { - $tail = $q[1]; - $text = $q[2]; + list( , $tail, $text ) = $q; } } @@ -2240,8 +2236,7 @@ class Parser { if ( $useLinkPrefixExtension ) { if ( preg_match( $e2, $s, $m ) ) { - $prefix = $m[2]; - $s = $m[1]; + list( , $s, $prefix ) = $m; } else { $prefix = ''; } diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php index 15c0cf9602..65b50e2d21 100644 --- a/includes/utils/UIDGenerator.php +++ b/includes/utils/UIDGenerator.php @@ -137,8 +137,7 @@ class UIDGenerator { $time = $info['time']; $counter = $info['offsetCounter']; } else { - $time = $info[0]; - $counter = $info[1]; + list( $time, $counter ) = $info; } // Take the 46 LSBs of "milliseconds since epoch" $id_bin = $this->millisecondsSinceEpochBinary( $time ); @@ -192,9 +191,7 @@ class UIDGenerator { $counter = $info['offsetCounter']; $clkSeq = $info['clkSeq']; } else { - $time = $info[0]; - $counter = $info[1]; - $clkSeq = $info[2]; + list( $time, $counter, $clkSeq ) = $info; } // Take the 46 LSBs of "milliseconds since epoch" $id_bin = $this->millisecondsSinceEpochBinary( $time ); diff --git a/languages/classes/LanguageKk_cyrl.php b/languages/classes/LanguageKk_cyrl.php index d695be1049..a89dbc2cac 100644 --- a/languages/classes/LanguageKk_cyrl.php +++ b/languages/classes/LanguageKk_cyrl.php @@ -63,9 +63,7 @@ class LanguageKk_cyrl extends Language { $secondPerson = [ "з" ]; // 1st plural, 2nd formal $thirdPerson = [ "ы", "і" ]; // 3rd - $lastLetter = $this->lastLetter( $word, $allVowels ); - $wordEnding =& $lastLetter[0]; - $wordLastVowel =& $lastLetter[1]; + list( $wordEnding, $wordLastVowel ) = $this->lastLetter( $word, $allVowels ); // Now convert the word switch ( $case ) { @@ -297,9 +295,7 @@ class LanguageKk_cyrl extends Language { $secondPerson = [ "z" ]; // 1st plural, 2nd formal $thirdPerson = [ "ı", "i" ]; // 3rd - $lastLetter = $this->lastLetter( $word, $allVowels ); - $wordEnding =& $lastLetter[0]; - $wordLastVowel =& $lastLetter[1]; + list( $wordEnding, $wordLastVowel ) = $this->lastLetter( $word, $allVowels ); // Now convert the word switch ( $case ) { @@ -531,9 +527,7 @@ class LanguageKk_cyrl extends Language { $secondPerson = [ "ز" ]; // 1st plural, 2nd formal $thirdPerson = [ "ى", "ٸ" ]; // 3rd - $lastLetter = $this->lastLetter( $word, $allVowels ); - $wordEnding = $lastLetter[0]; - $wordLastVowel = $lastLetter[1]; + list( $wordEnding, $wordLastVowel ) = $this->lastLetter( $word, $allVowels ); // Now convert the word switch ( $case ) { @@ -737,7 +731,7 @@ class LanguageKk_cyrl extends Language { /** * @param string $word - * @param array $allVowels + * @param string[] $allVowels * @return array */ function lastLetter( $word, $allVowels ) { diff --git a/maintenance/cleanupInvalidDbKeys.php b/maintenance/cleanupInvalidDbKeys.php index abae4f4379..eb45cfcce8 100644 --- a/maintenance/cleanupInvalidDbKeys.php +++ b/maintenance/cleanupInvalidDbKeys.php @@ -121,8 +121,7 @@ TEXT * @param array $tableParams A child array of self::$tables */ protected function cleanupTable( $tableParams ) { - $table = $tableParams[0]; - $prefix = $tableParams[1]; + list( $table, $prefix ) = $tableParams; $idField = $tableParams['idField'] ?? "{$prefix}_id"; $nsField = $tableParams['nsField'] ?? "{$prefix}_namespace"; $titleField = $tableParams['titleField'] ?? "{$prefix}_title"; diff --git a/maintenance/includes/BackupDumper.php b/maintenance/includes/BackupDumper.php index 3ae7f48955..425bf36c38 100644 --- a/maintenance/includes/BackupDumper.php +++ b/maintenance/includes/BackupDumper.php @@ -163,8 +163,7 @@ abstract class BackupDumper extends Maintenance { $options = $this->orderedOptions; foreach ( $options as $arg ) { - $opt = $arg[0]; - $param = $arg[1]; + list( $opt, $param ) = $arg; switch ( $opt ) { case 'plugin': diff --git a/maintenance/mysql.php b/maintenance/mysql.php index 34a6cb6951..c1e403cd3a 100644 --- a/maintenance/mysql.php +++ b/maintenance/mysql.php @@ -137,9 +137,7 @@ class MysqlMaintenance extends Maintenance { } elseif ( substr_count( $realServer, ':' ) == 1 ) { // If we have a colon and something that's not a port number // inside the hostname, assume it's the socket location - $hostAndSocket = explode( ':', $realServer, 2 ); - $realServer = $hostAndSocket[0]; - $socket = $hostAndSocket[1]; + list( $realServer, $socket ) = explode( ':', $realServer, 2 ); } if ( $dbName === false ) { diff --git a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php index 4a171dfac0..58f83decba 100644 --- a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php +++ b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php @@ -42,8 +42,7 @@ class QueryAllSpecialPagesTest extends MediaWikiTestCase { parent::__construct(); foreach ( QueryPage::getPages() as $page ) { - $class = $page[0]; - $name = $page[1]; + list( $class, $name ) = $page; if ( !in_array( $class, $this->manualTest ) ) { $this->queryPages[$class] = MediaWikiServices::getInstance()->getSpecialPageFactory()->getPage( $name );