| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 6361 | public function filterValue($value): string |
|
| 19 | { |
||
| 20 | // Force value as string representation of the number |
||
| 21 | 6361 | $number = (is_numeric($value) ? strval($value) : $value) ?: '0'; |
|
| 22 | |||
| 23 | // Check if some digit is invalid |
||
| 24 | 6361 | $invalid = array_diff_key( |
|
| 25 | 6361 | array_flip(str_split($number)), |
|
| 26 | 6361 | $this->getMap() |
|
| 27 | 6361 | ); |
|
| 28 | |||
| 29 | 6361 | if (!empty($invalid)) { |
|
| 30 | 2 | uksort($invalid, 'strnatcasecmp'); |
|
| 31 | |||
| 32 | 2 | throw new InvalidArgumentException(sprintf( |
|
| 33 | 2 | 'Found %s invalid characters "%s" on number "%s"', |
|
| 34 | 2 | (string) $this, |
|
| 35 | 2 | implode('', array_keys($invalid)), |
|
| 36 | 2 | $number |
|
| 37 | 2 | )); |
|
| 38 | } |
||
| 39 | |||
| 40 | 6359 | return $number; |
|
| 41 | } |
||
| 53 |