Completed
Push — master ( c29848...6d2813 )
by Gabriel
02:24
created

strToASCII()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 78
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 75
c 1
b 0
f 1
dl 0
loc 78
ccs 0
cts 2
cp 0
rs 8.5454
cc 1
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
if (!function_exists('fix_input_quotes')) {
4
    function fix_input_quotes()
5
    {
6
        if (get_magic_quotes_gpc()) {
7
            array_stripslashes($_GET);
8
            array_stripslashes($_POST);
9
            array_stripslashes($_COOKIE);
10
        }
11
    }
12
}
13
14
if (!function_exists('array_stripslashes')) {
15
    function array_stripslashes(&$array)
16
    {
17
        if (!is_array($array)) {
18
            return;
19
        }
20
        foreach ($array as $k => $v) {
21
            if (is_array($array[$k])) {
22
                array_stripslashes($array[$k]);
23
            } else {
24
                $array[$k] = stripslashes($array[$k]);
25
            }
26
        }
27
        return $array;
28
    }
29
}
30
31
if (!function_exists('clean')) {
32
    function clean($input)
33
    {
34
        return trim(stripslashes(htmlentities($input, ENT_QUOTES, 'UTF-8')));
35
    }
36
}
37
38
if (!function_exists('strToASCII')) {
39
    function strToASCII($str)
40
    {
41
        $trans = [
42
            'Š' => 'S',
43
            'Ș' => 'S',
44
            'š' => 's',
45
            'ș' => 's',
46
            'Ð' => 'Dj',
47
            'Ž' => 'Z',
48
            'ž' => 'z',
49
            'À' => 'A',
50
            'Á' => 'A',
51
            'Â' => 'A',
52
            'Ã' => 'A',
53
            'Ä' => 'A',
54
            'Ă' => 'A',
55
            'Å' => 'A',
56
            'Æ' => 'A',
57
            'Ç' => 'C',
58
            'È' => 'E',
59
            'É' => 'E',
60
            'Ê' => 'E',
61
            'Ë' => 'E',
62
            'Ì' => 'I',
63
            'Í' => 'I',
64
            'Î' => 'I',
65
            'Ï' => 'I',
66
            'Ñ' => 'N',
67
            'Ò' => 'O',
68
            'Ó' => 'O',
69
            'Ô' => 'O',
70
            'Õ' => 'O',
71
            'Ö' => 'O',
72
            'Ø' => 'O',
73
            'Ù' => 'U',
74
            'Ú' => 'U',
75
            'Ț' => 'T',
76
            'Û' => 'U',
77
            'Ü' => 'U',
78
            'Ý' => 'Y',
79
            'Þ' => 'B',
80
            'ß' => 'Ss',
81
            'à' => 'a',
82
            'á' => 'a',
83
            'â' => 'a',
84
            'ã' => 'a',
85
            'ä' => 'a',
86
            'ă' => 'a',
87
            'å' => 'a',
88
            'æ' => 'a',
89
            'ç' => 'c',
90
            'è' => 'e',
91
            'é' => 'e',
92
            'ê' => 'e',
93
            'ë' => 'e',
94
            'ì' => 'i',
95
            'í' => 'i',
96
            'î' => 'i',
97
            'ï' => 'i',
98
            'ð' => 'o',
99
            'ñ' => 'n',
100
            'ò' => 'o',
101
            'ó' => 'o',
102
            'ô' => 'o',
103
            'õ' => 'o',
104
            'ö' => 'o',
105
            'ø' => 'o',
106
            'ù' => 'u',
107
            'ú' => 'u',
108
            'û' => 'u',
109
            'ý' => 'y',
110
            'ý' => 'y',
111
            'þ' => 'b',
112
            'ÿ' => 'y',
113
            'ƒ' => 'f',
114
            'ț' => 't'
115
        ];
116
        return strtr($str, $trans);
117
    }
118
}
119
120
if (!function_exists('value')) {
121
    /**
122
     * Return the default value of the given value.
123
     *
124
     * @param  mixed $value
125
     * @return mixed
126
     */
127
    function value($value)
128
    {
129
        return $value instanceof Closure ? $value() : $value;
130
    }
131
}
132