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\Tag\EmptyTag; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Meta |
12
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
final class Meta extends AbstractElement |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
public function __construct(AttributeSet $attributes = null) |
17
|
|
|
{ |
18
|
|
|
$this->attributes = $attributes ?? new AttributeSet(); |
19
|
|
|
$this->tag = new EmptyTag('meta', $attributes); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function withAttribute(string $name, string $value = null): Meta |
23
|
|
|
{ |
24
|
|
|
if ($value) { |
|
|
|
|
25
|
|
|
$attribute = new StandardAttribute($name, $value); |
26
|
|
|
} else { |
27
|
|
|
$attribute = new BooleanAttribute($name); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
return new Meta($this->attributes->add($attribute)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $charset |
35
|
|
|
* @return Meta |
36
|
|
|
* @see http://www.iana.org/assignments/character-sets |
37
|
|
|
*/ |
38
|
|
|
public function withCharset(string $charset): Meta |
39
|
|
|
{ |
40
|
|
|
return $this->withAttribute('charset', $charset); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function withContent(string $content): Meta |
44
|
|
|
{ |
45
|
|
|
return $this->withAttribute('content', $content); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function withHttpEquiv(string $httpEquiv): Meta |
49
|
|
|
{ |
50
|
|
|
return $this->withAttribute('http-equiv', $httpEquiv); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $name |
55
|
|
|
* @return Meta |
56
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-name |
57
|
|
|
*/ |
58
|
|
|
public function withName(string $name): Meta |
59
|
|
|
{ |
60
|
|
|
return $this->withAttribute('name', $name); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.