Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Radio | |
100.00% |
12 / 12 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setValue | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| resetValue | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| check | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| uncheck | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isChecked | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Form\Element\Input; |
| 16 | |
| 17 | use Pop\Form\Element; |
| 18 | |
| 19 | /** |
| 20 | * Form radio element class |
| 21 | * |
| 22 | * @category Pop |
| 23 | * @package Pop\Form |
| 24 | * @author Nick Sagona, III <nick@popphp.org> |
| 25 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 26 | * @license https://www.popphp.org/license New BSD License |
| 27 | * @version 5.0.0 |
| 28 | */ |
| 29 | |
| 30 | class Radio extends Element\Input |
| 31 | { |
| 32 | /** |
| 33 | * Constructor |
| 34 | * |
| 35 | * Instantiate the text input form element |
| 36 | * |
| 37 | * @param string $name |
| 38 | * @param ?string $value |
| 39 | * @param ?string $indent |
| 40 | */ |
| 41 | public function __construct(string $name, ?string $value = null, ?string $indent = null) |
| 42 | { |
| 43 | parent::__construct($name, 'radio', $value, $indent); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Set the value of the form input element object |
| 48 | * |
| 49 | * @param mixed $value |
| 50 | * @return Radio |
| 51 | */ |
| 52 | public function setValue(mixed $value = null): Radio |
| 53 | { |
| 54 | if ($value == $this->getAttribute('value')) { |
| 55 | $this->check(); |
| 56 | } else { |
| 57 | $this->uncheck(); |
| 58 | } |
| 59 | return $this; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Reset the value of the form element |
| 64 | * |
| 65 | * @return Radio |
| 66 | */ |
| 67 | public function resetValue(): Radio |
| 68 | { |
| 69 | $this->uncheck(); |
| 70 | return $this; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Set the checkbox to checked |
| 75 | * |
| 76 | * @return Radio |
| 77 | */ |
| 78 | public function check(): Radio |
| 79 | { |
| 80 | $this->setAttribute('checked', 'checked'); |
| 81 | return $this; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Set the checkbox to checked |
| 86 | * |
| 87 | * @return Radio |
| 88 | */ |
| 89 | public function uncheck(): Radio |
| 90 | { |
| 91 | $this->removeAttribute('checked'); |
| 92 | return $this; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Determine if the radio value is checked |
| 97 | * |
| 98 | * @return bool |
| 99 | */ |
| 100 | public function isChecked(): bool |
| 101 | { |
| 102 | return ($this->getAttribute('checked') == 'checked'); |
| 103 | } |
| 104 | |
| 105 | } |