Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.00% |
6 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
UnknownLanguage | |
50.00% |
6 / 12 |
|
0.00% |
0 / 2 |
4.12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
asApiMessage | |
60.00% |
6 / 10 |
|
0.00% |
0 / 1 |
2.26 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace Wikibase\Lexeme\MediaWiki\Api\Error; |
6 | |
7 | use MediaWiki\Message\Message; |
8 | |
9 | /** |
10 | * @license GPL-2.0-or-later |
11 | */ |
12 | class UnknownLanguage implements ApiError { |
13 | /** |
14 | * @var string |
15 | */ |
16 | private $given; |
17 | |
18 | /** @var string|null */ |
19 | private $termText; |
20 | |
21 | /** |
22 | * @param string $given |
23 | * @param string|null $termText for context, if available |
24 | */ |
25 | public function __construct( string $given, $termText = null ) { |
26 | $this->given = $given; |
27 | $this->termText = $termText; |
28 | } |
29 | |
30 | public function asApiMessage( $parameterName, array $path ) { |
31 | if ( $this->termText !== null ) { |
32 | $message = new Message( |
33 | 'apierror-wikibaselexeme-unknown-language-withtext', |
34 | [ $parameterName, implode( '/', $path ), $this->given, $this->termText ] |
35 | ); |
36 | } else { |
37 | $message = new Message( |
38 | 'apierror-wikibaselexeme-unknown-language', |
39 | [ $parameterName, implode( '/', $path ), $this->given ] |
40 | ); |
41 | } |
42 | return new \ApiMessage( $message, 'not-recognized-language' ); |
43 | } |
44 | |
45 | } |