Conditions | 4 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 4 |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | 80 | protected function sanitize(int|string|float|null $number): string |
|
17 | { |
||
18 | 80 | if (is_float($number) && ! $this->is_good_float($number)) { |
|
19 | throw new LengthException(); |
||
20 | 80 | } |
|
21 | 10 | ||
22 | 10 | $number = str((string) $number)->replace(',', '.'); |
|
23 | 10 | ||
24 | 10 | $dots = $number->substrCount('.'); |
|
25 | |||
26 | if ($dots >= 2) { |
||
27 | $number = $number |
||
28 | 80 | ->replaceLast('.', ',') |
|
29 | 80 | ->replace('.', '') |
|
30 | ->replaceLast(',', '.'); |
||
31 | } |
||
32 | |||
33 | return $number |
||
34 | ->replaceMatches('/[^0-9.]/', '') |
||
35 | ->toString(); |
||
36 | } |
||
63 |