Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ThinMessage | |
0.00% |
0 / 10 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
setRow | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setTranslation | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
translation | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getProperty | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
getPropertyNames | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types=1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\MessageLoading; |
5 | |
6 | use stdClass; |
7 | |
8 | /** |
9 | * Message object which is based on database result row. Hence the name thin. |
10 | * Needs fields rev_user_text and those that are needed for loading revision |
11 | * text. |
12 | * |
13 | * @author Niklas Laxström |
14 | * @copyright Copyright © 2008-2010, Niklas Laxström |
15 | * @license GPL-2.0-or-later |
16 | */ |
17 | class ThinMessage extends Message { |
18 | /** This maps properties to fields in the database result row */ |
19 | protected static array $propertyMap = [ |
20 | 'last-translator-text' => 'rev_user_text', |
21 | 'last-translator-id' => 'rev_user', |
22 | ]; |
23 | /** Database Result Row */ |
24 | protected ?stdClass $row = null; |
25 | /** Stored translation. */ |
26 | protected ?string $translation = null; |
27 | |
28 | /** |
29 | * Set the database row this message is based on. |
30 | * @param stdClass $row Database Result Row |
31 | */ |
32 | public function setRow( stdClass $row ): void { |
33 | $this->row = $row; |
34 | } |
35 | |
36 | /** Set the current translation of this message. */ |
37 | public function setTranslation( string $text ): void { |
38 | $this->translation = $text; |
39 | } |
40 | |
41 | /** @inheritDoc */ |
42 | public function translation(): ?string { |
43 | if ( $this->row === null ) { |
44 | return $this->infile(); |
45 | } |
46 | return $this->translation; |
47 | } |
48 | |
49 | // Re-implemented |
50 | public function getProperty( string $key ) { |
51 | if ( !isset( self::$propertyMap[$key] ) ) { |
52 | return parent::getProperty( $key ); |
53 | } |
54 | $field = self::$propertyMap[$key]; |
55 | return $this->row->$field ?? null; |
56 | } |
57 | |
58 | // Re-implemented |
59 | public function getPropertyNames(): array { |
60 | return array_merge( parent::getPropertyNames(), array_keys( self::$propertyMap ) ); |
61 | } |
62 | } |