Completed
Pull Request — master (#3)
by thomas
18:16
created

PinRequest::getOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\PinEntry;
6
7
class PinRequest
8
{
9
    /**
10
     * keyed by the command, here we store a command => param map
11
     * @var string[]|int[]
12
     */
13
    private $commands = [];
14
15
    /**
16
     * @return string[]|int[]
17
     */
18
    public function getCommands(): array
19 2
    {
20
        return $this->commands;
21 2
    }
22 2
23
    private function withCommand(string $command, $param)
24
    {
25 1
        $this->commands[$command] = $param;
26
    }
27 1
28
    private function hasCommand(string $command): bool
29
    {
30 1
        return array_key_exists($command, $this->commands);
31
    }
32 1
33 1
    private function getCommand(string $command)
34
    {
35 1
        if (!$this->hasCommand($command)) {
36
            return null;
37
        }
38
        return $this->commands[$command];
39
    }
40
41 1
    public function withDesc(string $desc)
42
    {
43 1
        $this->withCommand(Command::SETDESC, $desc);
44
        return $this;
45
    }
46
47
    public function hasDesc(): bool
48
    {
49 1
        return $this->hasCommand(Command::SETDESC);
50
    }
51 1
52
    public function getDesc()
53
    {
54 14
        return $this->getCommand(Command::SETDESC);
55
    }
56 14
57 14
    public function withPrompt(string $desc)
58
    {
59 13
        $this->withCommand(Command::SETPROMPT, $desc);
60
        return $this;
61 13
    }
62
63
    public function hasPrompt(): bool
64 13
    {
65
        return $this->hasCommand(Command::SETPROMPT);
66 13
    }
67 13
68
    public function getPrompt()
69 13
    {
70
        return $this->getCommand(Command::SETPROMPT);
71
    }
72 2
73
    public function withKeyInfo(string $keyInfo)
74 2
    {
75 2
        $this->withCommand(Command::SETKEYINFO, $keyInfo);
76
        return $this;
77
    }
78 1
79
    public function hasKeyInfo(): bool
80 1
    {
81
        return $this->hasCommand(Command::SETKEYINFO);
82
    }
83 1
84
    public function getKeyInfo()
85 1
    {
86
        return $this->getCommand(Command::SETKEYINFO);
87
    }
88 1
89
    public function withRepeat($repeat)
90 1
    {
91 1
        $this->withCommand(Command::SETREPEAT, $repeat);
92
        return $this;
93
    }
94 1
95
    public function hasRepeat(): bool
96 1
    {
97
        return $this->hasCommand(Command::SETREPEAT);
98
    }
99 1
100
    public function getRepeat()
101 1
    {
102
        return $this->getCommand(Command::SETREPEAT);
103
    }
104 1
105
    public function withRepeatError(string $repeatError)
106 1
    {
107 1
        $this->withCommand(Command::SETREPEATERROR, $repeatError);
108
        return $this;
109
    }
110 1
111
    public function hasRepeatError(): bool
112 1
    {
113
        return $this->hasCommand(Command::SETREPEATERROR);
114
    }
115 1
116
    public function getRepeatError()
117 1
    {
118
        return $this->getCommand(Command::SETREPEATERROR);
119
    }
120 1
121
    public function withError(string $error)
122 1
    {
123 1
        $this->withCommand(Command::SETERROR, $error);
124
        return $this;
125
    }
126 1
127
    public function hasError(): bool
128 1
    {
129
        return $this->hasCommand(Command::SETERROR);
130
    }
131 1
132
    public function getError()
133 1
    {
134
        return $this->getCommand(Command::SETERROR);
135
    }
136
137
    public function withOkButton(string $ok)
138
    {
139
        $this->withCommand(Command::SETOK, $ok);
140 1
        return $this;
141
    }
142 1
143 1
    public function hasOkButton(): bool
144
    {
145
        return $this->hasCommand(Command::SETOK);
146 1
    }
147
148 1
    public function getOkButton()
149
    {
150
        return $this->getCommand(Command::SETOK);
151 1
    }
152
153 1
    public function withNotOk(string $ok)
154
    {
155
        $this->withCommand(Command::SETNOTOK, $ok);
156 1
        return $this;
157
    }
158 1
159 1
    public function hasNotOk(): bool
160
    {
161
        return $this->hasCommand(Command::SETNOTOK);
162 1
    }
163
164 1
    public function getNotOk()
165
    {
166
        return $this->getCommand(Command::SETNOTOK);
167 1
    }
168
169 1
    public function withCancelButton(string $cancel)
170
    {
171
        $this->withCommand(Command::SETCANCEL, $cancel);
172 1
        return $this;
173
    }
174 1
175 1
    public function hasCancelButton(): bool
176
    {
177
        return $this->hasCommand(Command::SETCANCEL);
178 1
    }
179
180 1
    public function getCancelButton()
181
    {
182
        return $this->getCommand(Command::SETCANCEL);
183 1
    }
184
185 1
    public function withTitle(string $title)
186
    {
187
        $this->withCommand(Command::SETTITLE, $title);
188 1
        return $this;
189
    }
190 1
191 1
    public function hasTitle(): bool
192
    {
193
        return $this->hasCommand(Command::SETTITLE);
194 1
    }
195
196 1
    public function getTitle()
197
    {
198
        return $this->getCommand(Command::SETTITLE);
199 1
    }
200
201 1
    public function withQualityBar(string $qualityBar)
202
    {
203
        $this->withCommand(Command::SETQUALITYBAR, $qualityBar);
204 1
        return $this;
205
    }
206 1
207 1
    public function hasQualityBar(): bool
208
    {
209
        return $this->hasCommand(Command::SETQUALITYBAR);
210 1
    }
211
212 1
    public function getQualityBar()
213
    {
214
        return $this->getCommand(Command::SETQUALITYBAR);
215 1
    }
216
217 1
    public function withQualityBarTooltip(string $tooltip)
218
    {
219
        $this->withCommand(Command::SETQUALITYBAR_TT, $tooltip);
220 2
        return $this;
221
    }
222 2
223 2
    public function hasQualityBarTooltip(): bool
224
    {
225
        return $this->hasCommand(Command::SETQUALITYBAR_TT);
226 1
    }
227
228 1
    public function getQualityBarTooltip()
229
    {
230
        return $this->getCommand(Command::SETQUALITYBAR_TT);
231 1
    }
232
233 1
    public function withTimeout(int $timeout)
234
    {
235
        $this->withCommand(Command::SETTIMEOUT, $timeout);
236 1
        return $this;
237
    }
238 1
239 1
    public function hasTimeout(): bool
240
    {
241
        return $this->hasCommand(Command::SETTIMEOUT);
242 1
    }
243
244 1
    public function getTimeout()
245
    {
246
        return $this->getCommand(Command::SETTIMEOUT);
247 1
    }
248
}
249