Radio::buildCheckboxes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\CLImate\TerminalObject\Dynamic;
4
5
class Radio extends Checkboxes
6
{
7
    /**
8
     * Build out the checkboxes
9
     *
10
     * @param array $options
11
     *
12
     * @return Checkbox\RadioGroup
13
     */
14 4
    protected function buildCheckboxes(array $options)
15
    {
16 4
        return new Checkbox\RadioGroup($options);
17
    }
18
19
    /**
20
     * Take the appropriate action based on the input character,
21
     * returns whether to stop listening or not
22
     *
23
     * @param string $char
24
     *
25
     * @return bool
26
     */
27
    protected function handleCharacter($char)
28
    {
29
        # Ignore space, as we can't select multiple options
30
        if ($char === " ") {
31
            return false;
32
        }
33
34
        # Use enter to select the current option
35
        if ($char === "\n") {
36
            $this->checkboxes->toggleCurrent();
37
        }
38
39
        return parent::handleCharacter($char);
40
    }
41
42
    /**
43
     * Format the prompt string
44
     *
45
     * @return string
46
     */
47
    protected function promptFormatted()
48
    {
49
        return $this->prompt . ' (press <Enter> to select)';
50
    }
51
}
52