Total Complexity | 15 |
Total Lines | 69 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class ValueParser |
||
6 | { |
||
7 | public function parse($input, $strict) |
||
8 | { |
||
9 | $input = $this->parseEmpty($input); |
||
10 | $input = $this->parseFloat($input); |
||
11 | $input = $this->parseNumeric($input); |
||
12 | $input = $this->parseBool($input, $strict); |
||
13 | |||
14 | return $input; |
||
15 | } |
||
16 | |||
17 | public function parseNumeric($input) |
||
18 | { |
||
19 | $var = filter_var($input, FILTER_VALIDATE_INT); |
||
20 | |||
21 | if (ctype_digit($input) || is_int($var)) { |
||
22 | return (int)$input; |
||
23 | } |
||
24 | |||
25 | return $input; |
||
26 | } |
||
27 | |||
28 | public function parseFloat($input) |
||
37 | } |
||
38 | |||
39 | public function parseBool($var, $strict) |
||
58 | } |
||
59 | |||
60 | public function parseEmpty($var) |
||
61 | { |
||
62 | if (strlen($var) === 0) { |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | return $var; |
||
67 | } |
||
68 | |||
69 | public function isBool($input) |
||
74 | } |
||
75 | } |