| Conditions | 3 |
| Paths | 2 |
| Total Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 2 | public function filterSingle($value, string $valueIdentifier = null) |
|
| 21 | { |
||
| 22 | 2 | $value = (string) $value; |
|
| 23 | // number is already normalized |
||
| 24 | 2 | $floatedValue =\floatval($value); |
|
| 25 | |||
| 26 | // check for the string length because: |
||
| 27 | // 1. floatval('12.456,67') returns 12.456 and |
||
| 28 | // 2. PHP returns true for '12.456,67' == 12.456 |
||
| 29 | 2 | if ($floatedValue == $value && strlen((string) $floatedValue) == strlen($value)) { |
|
| 30 | 1 | return $floatedValue; |
|
| 31 | } |
||
| 32 | |||
| 33 | // attempt to normalize it: |
||
| 34 | // remove spaces and thousands separator |
||
| 35 | // replace local decimal point with . |
||
| 36 | 1 | $value = strtr($value, array( |
|
| 37 | 1 | ' ' => '', |
|
| 38 | 1 | $this->options[self::OPTION_THOUSANDS_SEPARATOR] => '', |
|
| 39 | 1 | $this->options[self::OPTION_DECIMAL_POINT] => '.' |
|
| 40 | )); |
||
| 41 | 1 | return\floatval($value); |
|
| 42 | } |
||
| 43 | } |
||
| 44 |