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

Confirm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A confirmed() 0 14 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