mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 15:04:02 +00:00
Simplify private listToText() implementation
Motivation is to make the code shorter and faster to read, and also perform better. Bug: T236260 Change-Id: I9186370a628833c1563eb5fa4f2e062fb27d6ed7
This commit is contained in:
parent
f743aa058e
commit
7f99a1bfe1
|
@ -1101,16 +1101,15 @@ class Cite {
|
|||
* @return string
|
||||
*/
|
||||
private function listToText( array $arr ) {
|
||||
$cnt = count( $arr );
|
||||
if ( $cnt === 1 ) {
|
||||
// Enforce always returning a string
|
||||
return (string)$arr[0];
|
||||
$lastElement = array_pop( $arr );
|
||||
|
||||
if ( $arr === [] ) {
|
||||
return (string)$lastElement;
|
||||
}
|
||||
|
||||
$sep = wfMessage( 'cite_references_link_many_sep' )->inContentLanguage()->plain();
|
||||
$and = wfMessage( 'cite_references_link_many_and' )->inContentLanguage()->plain();
|
||||
$t = array_slice( $arr, 0, $cnt - 1 );
|
||||
return implode( $sep, $t ) . $and . $arr[$cnt - 1];
|
||||
return implode( $sep, $arr ) . $and . $lastElement;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue