| Conditions | 2 |
| Paths | 1 |
| Total Lines | 19 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 2 |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 13 | 10 | public static function toAscii($string) |
|
| 14 | { |
||
| 15 | 10 | $alnumPattern = '/^[a-zA-Z0-9 ]+$/'; |
|
| 16 | |||
| 17 | 10 | $string = iconv( |
|
| 18 | 10 | mb_detect_encoding($string), |
|
| 19 | 10 | 'ASCII//TRANSLIT', |
|
| 20 | 10 | $string |
|
| 21 | ); |
||
| 22 | |||
| 23 | 10 | $ret = array_map(function ($chr) use ($alnumPattern) { |
|
| 24 | 10 | if (preg_match($alnumPattern, $chr)) { |
|
| 25 | 10 | return $chr; |
|
| 26 | } |
||
| 27 | 10 | return ''; |
|
| 28 | 10 | }, str_split($string)); |
|
| 29 | |||
| 30 | 10 | return implode($ret); |
|
| 31 | } |
||
| 32 | } |
||
| 33 |