| Total Complexity | 8 |
| Total Lines | 92 |
| Duplicated Lines | 0 % |
| Coverage | 84.21% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | class ChoiceView |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * The label displayed to humans. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $label; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The view representation of the choice. |
||
| 28 | * |
||
| 29 | * @var mixed |
||
| 30 | */ |
||
| 31 | private $value; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The view representation of the choice. |
||
| 35 | * |
||
| 36 | * @var boolean |
||
| 37 | */ |
||
| 38 | private $selected; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Creates a new choice view. |
||
| 42 | * |
||
| 43 | * @param mixed $value The option value |
||
| 44 | * @param string|int $label The label displayed to humans |
||
| 45 | * @param boolean $selected This choice is selected |
||
| 46 | */ |
||
| 47 | 15 | public function __construct($value, $label, bool $selected = false) |
|
| 48 | { |
||
| 49 | 15 | $this->value = $value; |
|
| 50 | 15 | $this->selected = $selected; |
|
| 51 | |||
| 52 | // If there is no label, we take the value as label |
||
| 53 | 15 | $this->label = !is_string($label) ? $value : $label; |
|
| 54 | 15 | } |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Get the display label |
||
| 58 | * If the label is not declared, return the value |
||
| 59 | * |
||
| 60 | * @return string |
||
| 61 | */ |
||
| 62 | 11 | public function label(): string |
|
| 63 | { |
||
| 64 | 11 | return $this->label; |
|
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param string $label |
||
| 69 | */ |
||
| 70 | public function setLabel(string $label): void |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Get the option value |
||
| 77 | * |
||
| 78 | * @return mixed |
||
| 79 | */ |
||
| 80 | 15 | public function value() |
|
| 81 | { |
||
| 82 | 15 | return $this->value; |
|
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param mixed $value |
||
| 87 | */ |
||
| 88 | 11 | public function setValue($value): void |
|
| 89 | { |
||
| 90 | 11 | $this->value = $value; |
|
| 91 | 11 | } |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Does the current option is selected ? |
||
| 95 | * |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | 12 | public function selected(): bool |
|
| 99 | { |
||
| 100 | 12 | return $this->selected; |
|
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param bool $selected |
||
| 105 | */ |
||
| 106 | 11 | public function setSelected(bool $selected): void |
|
| 109 | 11 | } |
|
| 110 | } |
||
| 111 |