Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
CanvasContentRule | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 | |
0.00% |
0 / 1 |
test | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
42 |
1 | <?php |
2 | |
3 | namespace pvc\html\rules\content_rules\permitted; |
4 | |
5 | use pvc\html\rules\AbstractRule; |
6 | use pvc\interfaces\html\attribute\AttributeWithValueInterface; |
7 | use pvc\interfaces\html\content_model\ContentPermission; |
8 | use pvc\interfaces\html\dom\DomNodeInterface; |
9 | use pvc\interfaces\html\rules\ContentRuleInterface; |
10 | |
11 | class CanvasContentRule extends AbstractRule implements ContentRuleInterface |
12 | { |
13 | public function test(DomNodeInterface $content): ContentPermission |
14 | { |
15 | if ($content->getDomElement()->hasName('a')) return ContentPermission::GRANTED; |
16 | if ($content->getDomElement()->hasName('button')) return ContentPermission::GRANTED; |
17 | if ($content->getDomElement()->hasName('input')) { |
18 | $typeAttribute = $content->getDomElement()->getAttribute('type'); |
19 | if ($typeAttribute !== null) { |
20 | assert($typeAttribute instanceof AttributeWithValueInterface); |
21 | if (in_array($typeAttribute->getValue(), ['checkbox', 'radio','button'])) { |
22 | return ContentPermission::GRANTED; |
23 | } |
24 | } |
25 | }; |
26 | return ContentPermission::NOT_APPLICABLE; |
27 | } |
28 | } |