Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
71.43% covered (warning)
71.43%
5 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RawMessage
83.33% covered (warning)
83.33%
5 / 6
50.00% covered (danger)
50.00%
1 / 2
3.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
 fetchMessage
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Language;
22
23use InvalidArgumentException;
24use MediaWiki\Message\Message;
25
26/**
27 * Variant of the Message class.
28 *
29 * Rather than treating the message key as a lookup
30 * value (which is passed to the MessageCache and
31 * translated as necessary), a RawMessage key is
32 * treated as the actual message.
33 *
34 * All other functionality (parsing, escaping, etc.)
35 * is preserved.
36 *
37 * @newable
38 * @since 1.21
39 */
40class RawMessage extends Message {
41
42    /**
43     * Call the parent constructor, then store the key as
44     * the message.
45     *
46     * @stable to call
47     * @see Message::__construct
48     *
49     * @param string $text Message to use.
50     * @param array $params Parameters for the message.
51     *
52     * @throws InvalidArgumentException
53     */
54    public function __construct( $text, $params = [] ) {
55        if ( !is_string( $text ) ) {
56            throw new InvalidArgumentException( '$text must be a string' );
57        }
58
59        parent::__construct( $text, $params );
60
61        // The key is the message.
62        $this->message = $text;
63    }
64
65    /**
66     * Fetch the message (in this case, the key).
67     *
68     * @return string
69     */
70    public function fetchMessage() {
71        // Just in case the message is unset somewhere.
72        $this->message ??= $this->key;
73
74        return $this->message;
75    }
76
77}
78
79/** @deprecated class alias since 1.40 */
80class_alias( RawMessage::class, 'RawMessage' );