Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
DomNode | |
0.00% |
0 / 19 |
|
0.00% |
0 / 11 |
210 | |
0.00% |
0 / 1 |
getDomElement | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getContentModel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasAttribute | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCategories | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasCategory | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
hasParentWith | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
hasAncestorWith | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
canAcceptContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace pvc\html\dom; |
4 | |
5 | use pvc\interfaces\html\attribute\AttributeInterface; |
6 | use pvc\interfaces\html\content_model\ContentCategory; |
7 | use pvc\interfaces\html\content_model\ContentModelInterface; |
8 | use pvc\interfaces\html\dom\DomCollectionInterface; |
9 | use pvc\interfaces\html\dom\DomElementInterface; |
10 | use pvc\interfaces\html\dom\DomNodeInterface; |
11 | use pvc\struct\tree\node\Treenode; |
12 | |
13 | |
14 | /** |
15 | * @extends Treenode<DomNodeInterface, DomCollectionInterface> |
16 | */ |
17 | class DomNode extends Treenode |
18 | { |
19 | protected DomElementInterface $domElement; |
20 | |
21 | protected ContentModelInterface $contentModel; |
22 | |
23 | public function getDomElement(): DomElementInterface |
24 | { |
25 | return $this->domElement; |
26 | } |
27 | |
28 | public function getContentModel(): ContentModelInterface |
29 | { |
30 | return $this->contentModel; |
31 | } |
32 | |
33 | public function getName(): ?string |
34 | { |
35 | return $this->getDomElement()->getName(); |
36 | } |
37 | |
38 | public function hasName(string $name): bool |
39 | { |
40 | return $this->getDomElement()->getName() === $name; |
41 | } |
42 | |
43 | public function getAttribute(string $name): ?AttributeInterface |
44 | { |
45 | return $this->getDomElement()->getAttribute($name); |
46 | } |
47 | |
48 | public function hasAttribute(string $name): bool |
49 | { |
50 | return $this->getDomElement()->getAttribute($name) !== null; |
51 | } |
52 | |
53 | /** |
54 | * @return int |
55 | */ |
56 | public function getCategories(): int |
57 | { |
58 | return $this->getContentModel()->getCategories(); |
59 | } |
60 | |
61 | public function hasCategory(ContentCategory $category): bool |
62 | { |
63 | return $this->getContentModel()->hasCategory($category); |
64 | } |
65 | |
66 | public function hasParentWith(callable $callback): bool |
67 | { |
68 | if ($this->getParent()) { |
69 | $result = $callback($this->getParent()); |
70 | } else { |
71 | $result = false; |
72 | } |
73 | assert(is_bool($result)); |
74 | return $result; |
75 | } |
76 | |
77 | public function hasAncestorWith(callable $callback): bool |
78 | { |
79 | if ($this->hasParentWith($callback)) return true; |
80 | /** |
81 | * @var DomNodeInterface|null $parent |
82 | */ |
83 | $parent = $this->getParent(); |
84 | if ($parent) { |
85 | return $parent->hasAncestorWith($callback); |
86 | } |
87 | return false; |
88 | } |
89 | |
90 | public function canAcceptContent(DomNodeInterface $domNode): bool |
91 | { |
92 | return $this->getContentModel()->canAcceptContent($domNode); |
93 | } |
94 | } |