Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LocalizedImportException
85.71% covered (warning)
85.71%
6 / 7
50.00% covered (danger)
50.00%
1 / 2
3.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
2.02
 getMessageObject
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace FileImporter\Exceptions;
4
5use MediaWiki\Message\Message;
6use Throwable;
7use Wikimedia\Message\MessageSpecifier;
8
9/**
10 * Logic has been taken form core class LocalizedException
11 * @todo move logic to a trait in core and use it from there?
12 *
13 * @license GPL-2.0-or-later
14 * @author Addshore
15 */
16class LocalizedImportException extends ImportException {
17
18    /** @var string|array|MessageSpecifier */
19    protected $messageSpec;
20
21    /**
22     * @param string|array|MessageSpecifier $messageSpec See Message::newFromSpecifier
23     * @param Throwable|null $previous The previous exception used for the exception chaining.
24     */
25    public function __construct( $messageSpec, ?Throwable $previous = null ) {
26        $this->messageSpec = $messageSpec;
27        $msg = $this->getMessageObject();
28        $code = str_replace( 'fileimporter-', '', $msg->getKey() );
29        if ( $msg->getLanguage()->getCode() !== 'qqx' ) {
30            // Re-use the localizable part for the internal exception message string, but in
31            // canonical English. Appears only in logging/debugging.
32            $msg = $msg->inLanguage( 'en' )->useDatabase( false );
33        }
34
35        parent::__construct( $msg->plain(), $code, $previous );
36    }
37
38    public function getMessageObject(): Message {
39        return Message::newFromSpecifier( $this->messageSpec );
40    }
41
42}