Confirm   A
last analyzed

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 4
cts 4
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 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