Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Event | |
100.00% |
5 / 5 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
isValidAttributeIdName | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
setScript | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getScript | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
5 | */ |
6 | declare(strict_types=1); |
7 | |
8 | namespace pvc\html\event; |
9 | |
10 | use pvc\html\attribute\AttributeSingleValue; |
11 | use pvc\html\err\InvalidAttributeValueException; |
12 | use pvc\interfaces\html\attribute\EventInterface; |
13 | |
14 | /** |
15 | * Class Event |
16 | */ |
17 | class Event extends AttributeSingleValue implements EventInterface |
18 | { |
19 | |
20 | /** |
21 | * isValidAttributeName |
22 | * @param string $name |
23 | * @return bool |
24 | * |
25 | * need to override the testing of the attribute id in the Attribute class because javascript |
26 | * event names are lower case, alphabetic only. This is different from the restrictions placed on all other |
27 | * attribute names. |
28 | */ |
29 | protected function isValidAttributeIdName(string $name): bool |
30 | { |
31 | $pattern = '/^[a-z]*$/'; |
32 | return (bool) preg_match($pattern, $name); |
33 | } |
34 | |
35 | /** |
36 | * setScript |
37 | * |
38 | * @param string $script |
39 | * |
40 | * @throws InvalidAttributeValueException |
41 | */ |
42 | public function setScript(string $script): void |
43 | { |
44 | $this->setValue($script); |
45 | } |
46 | |
47 | /** |
48 | * getScript |
49 | * @return ?string |
50 | */ |
51 | public function getScript(): ?string |
52 | { |
53 | assert(is_string($value = $this->getValue())); |
54 | return $value; |
55 | } |
56 | } |