Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
LocalizedHttpException
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 3
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
6
 getMessageValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getErrorKey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace MediaWiki\Rest;
4
5use Wikimedia\Message\DataMessageValue;
6use Wikimedia\Message\MessageValue;
7
8/**
9 * @newable
10 */
11class LocalizedHttpException extends HttpException {
12    private MessageValue $messageValue;
13    private string $errorKey;
14
15    /**
16     * @stable to call
17     *
18     * @param MessageValue $messageValue
19     * @param int $code
20     * @param array $errorData
21     */
22    public function __construct( MessageValue $messageValue, $code = 500, $errorData = [] ) {
23        if ( $messageValue instanceof DataMessageValue ) {
24            $errorKey = $messageValue->getCode();
25            $errorData += $messageValue->getData() ?? [];
26        } else {
27            $errorKey = $messageValue->getKey();
28        }
29        parent::__construct(
30            'Localized exception with key ' . $messageValue->getKey(), $code, $errorData
31        );
32        $this->messageValue = $messageValue;
33        $this->errorKey = $errorKey;
34    }
35
36    public function getMessageValue(): MessageValue {
37        return $this->messageValue;
38    }
39
40    public function getErrorKey(): string {
41        return $this->errorKey;
42    }
43}