Completed
Push — master ( 900626...4b600e )
by
unknown
02:13
created

HtmlTableCellBuilder::toHtml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace WikibaseQuality\ConstraintReport\Html;
4
5
use Html;
6
use InvalidArgumentException;
7
use Wikimedia\Assert\Assert;
8
9
/**
10
 * @author BP2014N1
11
 * @license GPL-2.0-or-later
12
 */
13
class HtmlTableCellBuilder {
14
15
	/**
16
	 * Html content of the cell.
17
	 *
18
	 * @var string
19
	 */
20
	private $content;
21
22
	/**
23
	 * @var array
24
	 */
25
	private $attributes;
26
27
	/**
28
	 * Determines, whether the content is raw html or should be escaped.
29
	 *
30
	 * @var bool
31
	 */
32
	private $isRawContent;
33
34
	/**
35
	 * @param string $content HTML
36
	 * @param array $attributes
37
	 * @param bool $isRawContent
38
	 *
39
	 * @throws InvalidArgumentException
40
	 */
41
	public function __construct( $content, array $attributes = [], $isRawContent = false ) {
42
		Assert::parameterType( 'string', $content, '$content' );
43
		Assert::parameterType( 'boolean', $isRawContent, '$isRawContent' );
44
45
		$this->content = $content;
46
		$this->attributes = $attributes;
47
		$this->isRawContent = $isRawContent;
48
	}
49
50
	/**
51
	 * @return string HTML
52
	 */
53
	public function getContent() {
54
		return $this->content;
55
	}
56
57
	/**
58
	 * @return array
59
	 */
60
	public function getAttributes() {
61
		return $this->attributes;
62
	}
63
64
	/**
65
	 * @return string HTML
66
	 */
67
	public function toHtml() {
68
		if ( $this->isRawContent ) {
69
			return Html::rawElement( 'td', $this->getAttributes(), $this->content );
70
		} else {
71
			return Html::element( 'td', $this->getAttributes(), $this->content );
72
		}
73
	}
74
75
}
76