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

Radio   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 0
loc 47
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCheckboxes() 0 4 1
A handleCharacter() 0 14 3
A promptFormatted() 0 4 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 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