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