Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
HtmlTableHeaderBuilder | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIsSortable | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toHtml | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace WikibaseQuality\ConstraintReport\Html; |
4 | |
5 | use HtmlArmor; |
6 | use InvalidArgumentException; |
7 | use MediaWiki\Html\Html; |
8 | use Wikimedia\Assert\Assert; |
9 | |
10 | /** |
11 | * @author BP2014N1 |
12 | * @license GPL-2.0-or-later |
13 | */ |
14 | class HtmlTableHeaderBuilder { |
15 | |
16 | /** |
17 | * Html content of the header |
18 | * |
19 | * @var string|HtmlArmor |
20 | */ |
21 | private $content; |
22 | |
23 | /** |
24 | * Determines, whether the column should be sortable or not. |
25 | * |
26 | * @var bool |
27 | */ |
28 | private $isSortable; |
29 | |
30 | /** |
31 | * @param string|HtmlArmor $content |
32 | * @param bool $isSortable |
33 | * |
34 | * @throws InvalidArgumentException |
35 | */ |
36 | public function __construct( $content, $isSortable = false ) { |
37 | Assert::parameterType( [ 'string', HtmlArmor::class ], $content, '$content' ); |
38 | Assert::parameterType( 'boolean', $isSortable, '$isSortable' ); |
39 | |
40 | $this->content = $content; |
41 | $this->isSortable = $isSortable; |
42 | } |
43 | |
44 | /** |
45 | * @return string HTML |
46 | */ |
47 | public function getContent() { |
48 | return HtmlArmor::getHtml( $this->content ); |
49 | } |
50 | |
51 | /** |
52 | * @return bool |
53 | */ |
54 | public function getIsSortable() { |
55 | return $this->isSortable; |
56 | } |
57 | |
58 | /** |
59 | * Returns header as html. |
60 | * |
61 | * @return string HTML |
62 | */ |
63 | public function toHtml() { |
64 | $attributes = [ 'role' => 'columnheader button' ]; |
65 | |
66 | if ( !$this->isSortable ) { |
67 | $attributes['class'] = 'unsortable'; |
68 | } |
69 | |
70 | return Html::rawElement( 'th', $attributes, $this->getContent() ); |
71 | } |
72 | |
73 | } |