Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
Message | |
0.00% |
0 / 15 |
|
0.00% |
0 / 12 |
182 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
key | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
definition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
translation | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
setInfile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
infile | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addTag | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasTag | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTags | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setProperty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
appendProperty | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getProperty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
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 | /** |
7 | * Interface for message objects used by MessageCollection. |
8 | * |
9 | * @author Niklas Laxström |
10 | * @copyright Copyright © 2008-2010, Niklas Laxström |
11 | * @license GPL-2.0-or-later |
12 | */ |
13 | abstract class Message { |
14 | /** Message display key. */ |
15 | protected string $key; |
16 | /** Message definition. */ |
17 | protected ?string $definition; |
18 | /** Committed in-file translation. */ |
19 | protected ?string $infile = null; |
20 | /** @var string[] Message tags. */ |
21 | protected array $tags = []; |
22 | /** Message properties. */ |
23 | protected array $props = []; |
24 | /** @var string[] Message reviewers. */ |
25 | protected array $reviewers = []; |
26 | |
27 | /** |
28 | * Creates new message object. |
29 | * |
30 | * @param string $key Unique key identifying this message. |
31 | * @param string|null $definition The authoritave definition of this message. |
32 | */ |
33 | public function __construct( string $key, ?string $definition ) { |
34 | $this->key = $key; |
35 | $this->definition = $definition; |
36 | } |
37 | |
38 | /** Get the message key. */ |
39 | public function key(): string { |
40 | return $this->key; |
41 | } |
42 | |
43 | /** |
44 | * Get the message definition. |
45 | * Message definition should not be empty, but sometimes is. |
46 | * See: https://phabricator.wikimedia.org/T285830 |
47 | */ |
48 | public function definition(): ?string { |
49 | return $this->definition; |
50 | } |
51 | |
52 | /** Get the message translation. */ |
53 | abstract public function translation(): ?string; |
54 | |
55 | /** Set the committed translation. */ |
56 | public function setInfile( string $text ): void { |
57 | $this->infile = $text; |
58 | } |
59 | |
60 | /** Returns the committed translation. */ |
61 | public function infile(): ?string { |
62 | return $this->infile; |
63 | } |
64 | |
65 | /** Add a tag for this message. */ |
66 | public function addTag( string $tag ): void { |
67 | $this->tags[] = $tag; |
68 | } |
69 | |
70 | /** Check if this message has a given tag. */ |
71 | public function hasTag( string $tag ): bool { |
72 | return in_array( $tag, $this->tags, true ); |
73 | } |
74 | |
75 | /** |
76 | * Return all tags for this message. |
77 | * @return string[] |
78 | */ |
79 | public function getTags(): array { |
80 | return $this->tags; |
81 | } |
82 | |
83 | /** |
84 | * @param string $key |
85 | * @param mixed $value |
86 | */ |
87 | public function setProperty( string $key, $value ): void { |
88 | $this->props[$key] = $value; |
89 | } |
90 | |
91 | /** |
92 | * @param string $key |
93 | * @param mixed $value |
94 | */ |
95 | public function appendProperty( string $key, $value ): void { |
96 | if ( !isset( $this->props[$key] ) ) { |
97 | $this->props[$key] = []; |
98 | } |
99 | $this->props[$key][] = $value; |
100 | } |
101 | |
102 | /** @return mixed */ |
103 | public function getProperty( string $key ) { |
104 | return $this->props[$key] ?? null; |
105 | } |
106 | |
107 | /** Get all the available property names. */ |
108 | public function getPropertyNames(): array { |
109 | return array_keys( $this->props ); |
110 | } |
111 | } |