Encoding   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 2
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toAscii() 0 19 2
1
<?php
2
3
namespace Lbc\Helper;
4
5
class Encoding
6
{
7
    /**
8
     * Replace accent and remove unknown chars
9
     *
10
     * @param string $string
11
     * @return string
12
     */
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