1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RoyallTheFourth\HtmlDocument\Element; |
4
|
|
|
|
5
|
|
|
use RoyallTheFourth\HtmlDocument\Attribute\BooleanAttribute; |
6
|
|
|
use RoyallTheFourth\HtmlDocument\Attribute\StandardAttribute; |
7
|
|
|
use RoyallTheFourth\HtmlDocument\Set\AttributeSet; |
8
|
|
|
use RoyallTheFourth\HtmlDocument\Set\ElementSet; |
9
|
|
|
use RoyallTheFourth\HtmlDocument\Tag\Standard; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class TableHeaderCell |
13
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/th |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
final class TableHeaderCell extends AbstractElement implements ParentElementInterface |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
public function __construct(AttributeSet $attributes = null, ElementSet $children = null) |
18
|
|
|
{ |
19
|
|
|
$this->attributes = $attributes ?? new AttributeSet(); |
20
|
|
|
$this->children = $children ?? new ElementSet(); |
21
|
|
|
$this->tag = new Standard('th', $attributes, $children); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function withAttribute(string $name, string $value = null): TableHeaderCell |
25
|
|
|
{ |
26
|
|
|
if ($value) { |
|
|
|
|
27
|
|
|
$attribute = new StandardAttribute($name, $value); |
28
|
|
|
} else { |
29
|
|
|
$attribute = new BooleanAttribute($name); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return new TableHeaderCell($this->attributes->add($attribute), $this->children); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function withChild(ElementInterface $element): TableHeaderCell |
36
|
|
|
{ |
37
|
|
|
return new TableHeaderCell($this->attributes, $this->children->add($element)); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function withColSpan(int $span): TableHeaderCell |
41
|
|
|
{ |
42
|
|
|
return $this->withAttribute('colspan', $span); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function withRowSpan(int $span): TableHeaderCell |
46
|
|
|
{ |
47
|
|
|
return $this->withAttribute('rowspan', $span); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function withHeaders(string $ids): TableHeaderCell |
51
|
|
|
{ |
52
|
|
|
return $this->withAttribute('headers', $ids); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function withScope(string $scope): TableHeaderCell |
56
|
|
|
{ |
57
|
|
|
return $this->withAttribute('scope', $scope); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.