Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
HtmlTableCellBuilder
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getContent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAttributes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toHtml
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace WikibaseQuality\ConstraintReport\Html;
4
5use HtmlArmor;
6use InvalidArgumentException;
7use MediaWiki\Html\Html;
8use Wikimedia\Assert\Assert;
9
10/**
11 * @author BP2014N1
12 * @license GPL-2.0-or-later
13 */
14class HtmlTableCellBuilder {
15
16    /**
17     * Html content of the cell.
18     *
19     * @var string|HtmlArmor
20     */
21    private $content;
22
23    /**
24     * @var array
25     */
26    private $attributes;
27
28    /**
29     * @param string|HtmlArmor $content
30     * @param array $attributes
31     *
32     * @throws InvalidArgumentException
33     */
34    public function __construct( $content, array $attributes = [] ) {
35        Assert::parameterType( [ 'string', HtmlArmor::class ], $content, '$content' );
36
37        $this->content = $content;
38        $this->attributes = $attributes;
39    }
40
41    /**
42     * @return string HTML
43     */
44    public function getContent() {
45        return HtmlArmor::getHtml( $this->content );
46    }
47
48    /**
49     * @return array
50     */
51    public function getAttributes() {
52        return $this->attributes;
53    }
54
55    /**
56     * @return string HTML
57     */
58    public function toHtml() {
59        return Html::rawElement( 'td', $this->getAttributes(), $this->getContent() );
60    }
61
62}