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:
Thiemo Kreuz 2019-10-25 10:17:05 +02:00
parent f743aa058e
commit 7f99a1bfe1

View file

@ -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;
}
/**