Completed
Push — master ( 627059...4c883f )
by Michael
9s
created

Text   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 89
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setPromptText() 0 6 1
A getPromptText() 0 4 1
A setValidationFailedText() 0 6 1
A getValidationFailedText() 0 4 1
A setPlaceholderText() 0 6 1
A getPlaceholderText() 0 4 1
A ask() 0 4 1
A validate() 0 4 1
A filter() 0 4 1
A getStyle() 0 4 1
1
<?php
2
3
namespace PhpSchool\CliMenu\Input;
4
5
use PhpSchool\CliMenu\MenuStyle;
6
7
/**
8
 * @author Aydin Hassan <[email protected]>
9
 */
10
class Text implements Input
11
{
12
    /**
13
     * @var InputIO
14
     */
15
    private $inputIO;
16
17
    /**
18
     * @var string
19
     */
20
    private $promptText = 'Enter text:';
21
22
    /**
23
     * @var string
24
     */
25
    private $validationFailedText = 'Invalid, try again';
26
27
    /**
28
     * @var string
29
     */
30
    private $placeholderText = '';
31
32
    /**
33
     * @var MenuStyle
34
     */
35
    private $style;
36
37
    public function __construct(InputIO $inputIO, MenuStyle $style)
38
    {
39
        $this->inputIO = $inputIO;
40
        $this->style = $style;
41
    }
42
43
    public function setPromptText(string $promptText) : Input
44
    {
45
        $this->promptText = $promptText;
46
47
        return $this;
48
    }
49
50
    public function getPromptText() : string
51
    {
52
        return $this->promptText;
53
    }
54
55
    public function setValidationFailedText(string $validationFailedText) : Input
56
    {
57
        $this->validationFailedText = $validationFailedText;
58
59
        return $this;
60
    }
61
62
    public function getValidationFailedText() : string
63
    {
64
        return $this->validationFailedText;
65
    }
66
67
    public function setPlaceholderText(string $placeholderText) : Input
68
    {
69
        $this->placeholderText = $placeholderText;
70
71
        return $this;
72
    }
73
74
    public function getPlaceholderText() : string
75
    {
76
        return $this->placeholderText;
77
    }
78
79
    public function ask() : InputResult
80
    {
81
        return $this->inputIO->collect($this);
82
    }
83
84
    public function validate(string $input) : bool
85
    {
86
        return !empty($input);
87
    }
88
89
    public function filter(string $value) : string
90
    {
91
        return $value;
92
    }
93
94
    public function getStyle() : MenuStyle
95
    {
96
        return $this->style;
97
    }
98
}
99