Completed
Push — version-4-wip ( 86a2b9...5c3ca2 )
by Craig
03:49
created

Radio::handleCharacter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 5
cts 6
cp 0.8333
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0416
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 4
    protected function handleCharacter($char)
28
    {
29
        # Ignore space, as we can't select multiple options
30 4
        if ($char === " ") {
31
            return false;
32
        }
33
34
        # Use enter to select the current option
35 4
        if ($char === "\n") {
36 4
            $this->checkboxes->toggleCurrent();
37
        }
38
39 4
        return parent::handleCharacter($char);
40
    }
41
42
    /**
43
     * Format the prompt string
44
     *
45
     * @return string
46
     */
47 4
    protected function promptFormatted()
48
    {
49 4
        return $this->prompt . ' (press <Enter> to select)';
50
    }
51
}
52