eddiriarte /
console-select
| 1 | <?php |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 2 | namespace EddIriarte\Console\Inputs; |
||
|
0 ignored issues
–
show
|
|||
| 3 | |||
| 4 | use EddIriarte\Console\Inputs\AbstractSelect; |
||
| 5 | use EddIriarte\Console\Inputs\Exceptions\UnknownOption; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Class CheckboxInput |
||
| 9 | * @package EddIriarte\Console\Inputs |
||
|
0 ignored issues
–
show
|
|||
| 10 | * @author Eduardo Iriarte <eddiriarte[at]gmail[dot]com> |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 11 | */ |
||
|
0 ignored issues
–
show
|
|||
| 12 | class CheckboxInput extends AbstractSelect |
||
| 13 | { |
||
|
0 ignored issues
–
show
|
|||
| 14 | /** |
||
|
0 ignored issues
–
show
|
|||
| 15 | * {@inheritdoc} |
||
| 16 | */ |
||
|
0 ignored issues
–
show
|
|||
| 17 | 7 | public function select(string $option): void |
|
|
0 ignored issues
–
show
|
|||
| 18 | { |
||
|
0 ignored issues
–
show
|
|||
| 19 | 7 | if (empty(array_intersect($this->options, [$option]))) { |
|
|
0 ignored issues
–
show
|
|||
| 20 | 1 | throw new UnknownOption($option); |
|
| 21 | } |
||
| 22 | |||
| 23 | 6 | if ($this->isSelected($option)) { |
|
| 24 | 1 | $this->selections = array_values(array_diff($this->selections, [$option])); |
|
|
0 ignored issues
–
show
|
|||
| 25 | } else { |
||
| 26 | 6 | $this->selections[] = $option; |
|
| 27 | } |
||
| 28 | 6 | } |
|
|
0 ignored issues
–
show
|
|||
| 29 | } |
||
|
0 ignored issues
–
show
|
|||
| 30 |