Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
InsertablesAid
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
20
0.00% covered (danger)
0.00%
0 / 1
 getData
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
6use MediaWiki\Extension\Translate\TranslatorInterface\TranslationHelperException;
7
8/**
9 * Translation aid that suggests insertables. Insertable is a string that
10 * usually does not need translation and is difficult to type manually.
11 * @ingroup TranslationAids
12 * @author Niklas Laxström
13 * @license GPL-2.0-or-later
14 * @since 2013.09
15 */
16class InsertablesAid extends TranslationAid {
17    public function getData(): array {
18        // We need to get the primary group to get the correct file
19        // So $group can be different from $this->group
20        $group = $this->handle->getGroup();
21
22        // This was added later, so not all classes have it. In addition
23        // the message group class hierarchy doesn't lend itself easily
24        // to the user of interfaces for this purpose.
25        if ( !method_exists( $group, 'getInsertablesSuggester' ) ) {
26            throw new TranslationHelperException( 'Group does not have insertable suggesters' );
27        }
28
29        // @phan-suppress-next-line PhanUndeclaredMethod
30        $suggester = $group->getInsertablesSuggester();
31
32        // It is okay to return null suggester
33        if ( !$suggester ) {
34            throw new TranslationHelperException( 'Group does not have insertable suggesters' );
35        }
36
37        $insertables = $suggester->getInsertables( $this->dataProvider->getDefinition() );
38        $blob = [];
39        foreach ( $insertables as $insertable ) {
40            $displayText = $insertable->getDisplayText();
41
42            // The keys are used for de-duplication
43            $blob[$displayText] = [
44                'display' => $displayText,
45                'pre' => $insertable->getPreText(),
46                'post' => $insertable->getPostText(),
47            ];
48        }
49
50        $blob = array_values( $blob );
51        $blob['**'] = 'insertable';
52
53        return $blob;
54    }
55}