Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
CanvasContentRule
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 1
 test
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
42
1<?php
2
3namespace pvc\html\rules\content_rules\permitted;
4
5use pvc\html\rules\AbstractRule;
6use pvc\interfaces\html\attribute\AttributeWithValueInterface;
7use pvc\interfaces\html\content_model\ContentPermission;
8use pvc\interfaces\html\dom\DomNodeInterface;
9use pvc\interfaces\html\rules\ContentRuleInterface;
10
11class 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}