Completed
Push — master ( 7d2382...4d33f4 )
by Craig
01:56
created

Confirm::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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