Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ParserBooleanTrueFalse | |
100.00% |
16 / 16 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
1 / 1 |
isCaseSensitive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setCaseSensitive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
parseValue | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
setMsgContent | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
4 | */ |
5 | |
6 | declare(strict_types=1); |
7 | |
8 | namespace pvc\parser\boolean; |
9 | |
10 | use pvc\interfaces\msg\MsgInterface; |
11 | use pvc\parser\Parser; |
12 | |
13 | /** |
14 | * Parse either the word 'true' or 'false' into a boolean. |
15 | * |
16 | * Class ParserBooleanTrueFalse. |
17 | * @extends Parser<bool> |
18 | */ |
19 | class ParserBooleanTrueFalse extends Parser |
20 | { |
21 | protected bool $caseSensitive = false; |
22 | |
23 | public function isCaseSensitive(): bool |
24 | { |
25 | return $this->caseSensitive; |
26 | } |
27 | |
28 | public function setCaseSensitive(bool $caseSensitive): void |
29 | { |
30 | $this->caseSensitive = $caseSensitive; |
31 | } |
32 | |
33 | /** |
34 | * @function parse |
35 | * @param string $data |
36 | * @return bool |
37 | */ |
38 | protected function parseValue(string $data): bool |
39 | { |
40 | if (!$this->isCaseSensitive()) { |
41 | $data = strtolower($data); |
42 | } |
43 | |
44 | if ($data === 'true') { |
45 | $this->parsedValue = true; |
46 | return true; |
47 | } |
48 | |
49 | if ($data === 'false') { |
50 | $this->parsedValue = false; |
51 | return true; |
52 | } |
53 | |
54 | return false; |
55 | } |
56 | |
57 | /** |
58 | * setMsgContent |
59 | * @param MsgInterface $msg |
60 | */ |
61 | protected function setMsgContent(MsgInterface $msg): void |
62 | { |
63 | $msgId = 'not_true_or_false'; |
64 | $text = 'case-sensitive'; |
65 | $text .= ($this->isCaseSensitive() ? '' : 'not ') . $text; |
66 | $msgParameters = ['caseSensitive' => $text]; |
67 | $msg->setContent($this->getMsgDomain(), $msgId, $msgParameters); |
68 | } |
69 | } |