Completed
Push — master ( a718f1...259f04 )
by
unknown
01:49
created

ViolationMessageRendererFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

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