Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LemmaTextSummaryFormatter
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSummary
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare( strict_types=1 );
4namespace Wikibase\Lexeme\Presentation\Content;
5
6use MediaWiki\Language\Language;
7use Wikibase\DataModel\Term\TermList;
8
9/**
10 * @license GPL-2.0-or-later
11 */
12class LemmaTextSummaryFormatter {
13
14    /**
15     * @var Language
16     */
17    private $language;
18
19    public function __construct( $contentLanguage ) {
20        $this->language = $contentLanguage;
21    }
22
23    /**
24     * @param TermList $lemmas
25     * @param int $maxLength
26     * @return string
27     */
28    public function getSummary( TermList $lemmas, int $maxLength ) {
29        if ( $lemmas->isEmpty() ) {
30            return '';
31        }
32
33        // Note: this assumes that only one lemma per language exists
34        $terms = array_values( $lemmas->toTextArray() );
35
36        return $this->language->truncateForDatabase(
37            $this->language->commaList( $terms ),
38            $maxLength
39        );
40    }
41
42}