| Total Complexity | 7 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | trait TChecked |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @param string|int|float|bool|null $value |
||
| 15 | */ |
||
| 16 | 8 | public function setValue($value): void |
|
| 17 | { |
||
| 18 | 8 | $this->setChecked($value); |
|
| 19 | 8 | } |
|
| 20 | |||
| 21 | 3 | public function getValue() |
|
| 22 | { |
||
| 23 | 3 | return $this->getChecked() ? $this->originalValue : '' ; |
|
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Set if radio is checked |
||
| 28 | * @param string|int|float|bool|null $value |
||
| 29 | * @return $this |
||
| 30 | */ |
||
| 31 | 8 | protected function setChecked($value): self |
|
| 32 | { |
||
| 33 | 8 | if (!empty($value) && ('none' !== strval($value))) { |
|
| 34 | 7 | $this->setAttribute('checked', 'checked'); |
|
| 35 | } else { |
||
| 36 | 5 | $this->removeAttribute('checked'); |
|
| 37 | } |
||
| 38 | 8 | return $this; |
|
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Get if radio is checked |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | 3 | protected function getChecked(): bool |
|
| 48 | } |
||
| 49 | |||
| 50 | abstract public function setAttribute(string $name, string $value): void; |
||
| 51 | |||
| 52 | abstract public function removeAttribute(string $name): void; |
||
| 53 | |||
| 54 | abstract public function getAttribute(string $name): ?string; |
||
| 55 | } |
||
| 56 |