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
This commit is contained in:
Thiemo Kreuz 2019-03-24 15:04:32 +01:00 committed by Thiemo Kreuz (WMDE)
parent 0449f653c7
commit 9314453c93
15 changed files with 24 additions and 59 deletions

View file

@ -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 ];
}

View file

@ -101,8 +101,7 @@ class LCStoreStaticArray implements LCStore {
return $encoded;
}
$type = $encoded[0];
$data = $encoded[1];
list( $type, $data ) = $encoded;
switch ( $type ) {
case 'a':

View file

@ -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 ) {

View file

@ -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 ) {

View file

@ -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;

View file

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

View file

@ -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 ) {

View file

@ -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'] ) ) {

View file

@ -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 = '';
}

View file

@ -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 );

View file

@ -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 ) {

View file

@ -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";

View file

@ -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':

View file

@ -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 ) {

View file

@ -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 );