Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ViolationMessageRendererFactory | |
0.00% |
0 / 18 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getViolationMessageRenderer | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Message; |
6 | |
7 | use MediaWiki\Config\Config; |
8 | use MediaWiki\Language\Language; |
9 | use MediaWiki\Languages\LanguageNameUtils; |
10 | use MessageLocalizer; |
11 | use ValueFormatters\FormatterOptions; |
12 | use Wikibase\Lib\Formatters\OutputFormatValueFormatterFactory; |
13 | use Wikibase\Lib\Formatters\SnakFormatter; |
14 | use Wikibase\Lib\TermLanguageFallbackChain; |
15 | use Wikibase\View\EntityIdFormatterFactory; |
16 | |
17 | /** |
18 | * @license GPL-2.0-or-later |
19 | */ |
20 | class ViolationMessageRendererFactory { |
21 | |
22 | private Config $config; |
23 | private LanguageNameUtils $languageNameUtils; |
24 | private EntityIdFormatterFactory $entityIdHtmlLinkFormatterFactory; |
25 | private OutputFormatValueFormatterFactory $valueFormatterFactory; |
26 | |
27 | public function __construct( |
28 | Config $config, |
29 | LanguageNameUtils $languageNameUtils, |
30 | EntityIdFormatterFactory $entityIdHtmlLinkFormatterFactory, |
31 | OutputFormatValueFormatterFactory $valueFormatterFactory |
32 | ) { |
33 | $this->config = $config; |
34 | $this->languageNameUtils = $languageNameUtils; |
35 | $this->entityIdHtmlLinkFormatterFactory = $entityIdHtmlLinkFormatterFactory; |
36 | $this->valueFormatterFactory = $valueFormatterFactory; |
37 | } |
38 | |
39 | public function getViolationMessageRenderer( |
40 | Language $userLanguage, |
41 | TermLanguageFallbackChain $languageFallbackChain, |
42 | MessageLocalizer $messageLocalizer |
43 | ): ViolationMessageRenderer { |
44 | $userLanguageCode = $userLanguage->getCode(); |
45 | $formatterOptions = new FormatterOptions(); |
46 | $formatterOptions->setOption( SnakFormatter::OPT_LANG, $userLanguageCode ); |
47 | return new MultilingualTextViolationMessageRenderer( |
48 | $this->entityIdHtmlLinkFormatterFactory |
49 | ->getEntityIdFormatter( $userLanguage ), |
50 | $this->valueFormatterFactory |
51 | ->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ), |
52 | $this->languageNameUtils, |
53 | $userLanguageCode, |
54 | $languageFallbackChain, |
55 | $messageLocalizer, |
56 | $this->config |
57 | ); |
58 | } |
59 | |
60 | } |