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

Confirm::confirmed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace League\CLImate\TerminalObject\Dynamic;
4
5
use League\CLImate\Util\Reader\ReaderInterface;
6
use function in_array;
7
use function strtolower;
8
use function substr;
9
10
class Confirm extends Input
11
{
12
13
14
    /**
15
     * @inheritdoc
16
     */
17 16
    public function __construct($prompt, ReaderInterface $reader = null)
18
    {
19 16
        parent::__construct($prompt, $reader);
20
21 16
        $this->default = "n";
22 16
    }
23
24
25
    /**
26
     * Let us know if the user confirmed.
27
     *
28
     * @return bool
29
     */
30 16
    public function confirmed()
31
    {
32 16
        if (in_array($this->default, ["y", "yes"], true)) {
33 4
            $this->prompt .= " [Y/n]";
34
        } else {
35 12
            $this->prompt .= " [y/N]";
36
        }
37
38 16
        $this->accept(['y', 'yes', 'n', 'no'], false);
39
40 16
        $response = strtolower($this->prompt());
41
42 16
        return (substr($response, 0, 1) === 'y');
43
    }
44
}
45