Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LocalizedImportException | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
3.03 | |
0.00% |
0 / 1 |
| __construct | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
2.02 | |||
| getMessageObject | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace FileImporter\Exceptions; |
| 4 | |
| 5 | use MediaWiki\Message\Message; |
| 6 | use Throwable; |
| 7 | use 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 | */ |
| 16 | class LocalizedImportException extends ImportException { |
| 17 | |
| 18 | /** @var string|array|MessageSpecifier */ |
| 19 | private $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 | } |