Completed
Push — master ( 3b681e...9217d6 )
by thomas
8s
created

PinRequest::hasRepeat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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