EscapePLCharsExtension::escapePLcharsFilter()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 112
Code Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 112
rs 8.2857
cc 1
eloc 85
nc 1
nop 1

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
namespace Hospitalplugin\Twig;
3
4
class EscapePLCharsExtension extends \Twig_Extension
5
{
6
7
    public function getFilters()
8
    {
9
        return array(
10
            new \Twig_SimpleFilter('escapePL', array(
11
                $this,
12
                'escapePLcharsFilter'
13
            ))
14
        );
15
    }
16
17
    public function escapePLcharsFilter($string)
18
    {
19
        $tabela = Array(
20
            "Ą" => "A",
21
            "ą" => "a",
22
            "Ć" => "C",
23
            "ć" => "c",
24
            "Ę" => "E",
25
            "ę" => "e",
26
            "Ł" => "L",
27
            "ł" => "l",
28
            "Ń" => "N",
29
            "ń" => "n",
30
            "Ó" => "O",
31
            "ó" => "o",
32
            "Ś" => "S",
33
            "ś" => "s",
34
            "Ż" => "Z",
35
            "ż" => "z",
36
            "Ź" => "Z",
37
            "ź" => "z",
38
            
39
            // WIN
40
            
41
            "xb9" => "a",
42
            "xa5" => "A",
43
            "xe6" => "c",
44
            "xc6" => "C",
45
            
46
            "xea" => "e",
47
            "xca" => "E",
48
            "xb3" => "l",
49
            "xa3" => "L",
50
            
51
            "xf3" => "o",
52
            "xd3" => "O",
53
            "x9c" => "s",
54
            "x8c" => "S",
55
            
56
            "x9f" => "z",
57
            "xaf" => "Z",
58
            "xbf" => "z",
59
            "xac" => "Z",
60
            
61
            "xf1" => "n",
62
            "xd1" => "N",
63
            
64
            // UTF
65
            
66
            "xc4x85" => "a",
67
            "xc4x84" => "A",
68
            "xc4x87" => "c",
69
            "xc4x86" => "C",
70
            
71
            "xc4x99" => "e",
72
            "xc4x98" => "E",
73
            "xc5x82" => "l",
74
            "xc5x81" => "L",
75
            
76
            "xc3xb3" => "o",
77
            "xc3x93" => "O",
78
            "xc5x9b" => "s",
79
            "xc5x9a" => "S",
80
            
81
            "xc5xbc" => "z",
82
            "xc5xbb" => "Z",
83
            "xc5xba" => "z",
84
            "xc5xb9" => "Z",
85
            
86
            "xc5x84" => "n",
87
            "xc5x83" => "N",
88
            
89
            // ISO
90
            
91
            "xb1" => "a",
92
            "xa1" => "A",
93
            "xe6" => "c",
94
            "xc6" => "C",
95
            
96
            "xea" => "e",
97
            "xca" => "E",
98
            "xb3" => "l",
99
            "xa3" => "L",
100
            
101
            "xf3" => "o",
102
            "xd3" => "O",
103
            "xb6" => "s",
104
            "xa6" => "S",
105
            
106
            "xbc" => "z",
107
            "xac" => "Z",
108
            "xbf" => "z",
109
            "xaf" => "Z",
110
            
111
            "xf1" => "n",
112
            "xd1" => "N",
113
            
114
            // minus hyphen #hash space
115
            "xc2xad" => "",
116
            "x2d" => "",
117
            "x23" => "",
118
            "x20" => "",
119
            "&ndash" => "",
120
            "-" => "",
121
            "#" => ""
122
        );
123
        
124
        $string = strtr($string, $tabela);
125
        $string = ucwords($string);
126
        $string = str_replace(' ', '', $string);
127
        return $string;
128
    }
129
130
    public function getName()
131
    {
132
        return 'escape_PL_chars_extension';
133
    }
134
}