BuzzExpertRender   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 133
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
B remplacerLesCaracteresSpeciaux() 0 118 4
A getSupport() 0 4 1
1
<?php
2
3
namespace Starkerxp\CampaignBundle\Render;
4
5
class BuzzExpertRender extends AbstractRender
6
{
7
    public function render()
8
    {
9
        $contenu = $this->remplacerLesCaracteresSpeciaux(mb_convert_encoding($this->contenu, 'UTF-8'));
10
11
        return $contenu;
12
    }
13
14
    public function remplacerLesCaracteresSpeciaux($contenu)
15
    {
16
        // Gestion des accents.
17
        $findAccent = [
18
            'Â',
19
            'â',
20
            'Á',
21
            'á',
22
            'Ã',
23
            'ã',
24
            'Ᾱ',
25
            'ᾱ',
26
            'Ç',
27
            'ç',
28
            'Č',
29
            'č',
30
            'Ć',
31
            'ć',
32
            'Ê',
33
            'ê',
34
            'Ë',
35
            'ë',
36
            'Ė',
37
            'ė',
38
            'ï',
39
            'Î',
40
            'î',
41
            'Í',
42
            'í',
43
            'ń',
44
            'Ô',
45
            'ô',
46
            'Ó',
47
            'ó',
48
            'Õ',
49
            'õ',
50
            'Œ',
51
            'œ',
52
            'Ō',
53
            'ō',
54
            'Ś',
55
            'ś',
56
            'Š',
57
            'š',
58
            'Û',
59
            'û',
60
            'Ū',
61
            'ū',
62
            'Ӱ',
63
            'ӱ',
64
        ];
65
        $replaceAccent = [
66
            'A',
67
            'a',
68
            'A',
69
            'a',
70
            'A',
71
            'a',
72
            'A',
73
            'a',
74
            'C',
75
            'c',
76
            'C',
77
            'c',
78
            'C',
79
            'c',
80
            'E',
81
            'e',
82
            'E',
83
            'e',
84
            'E',
85
            'e',
86
            'i',
87
            'I',
88
            'i',
89
            'I',
90
            'i',
91
            'n',
92
            'O',
93
            'o',
94
            'O',
95
            'o',
96
            'O',
97
            'o',
98
            'oe',
99
            'oe',
100
            'O',
101
            'o',
102
            'S',
103
            's',
104
            'S',
105
            's',
106
            'U',
107
            'u',
108
            'U',
109
            'u',
110
            'Y',
111
            'y',
112
        ];
113
        $contenu = str_replace($findAccent, $replaceAccent, $contenu);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $contenu. This often makes code more readable.
Loading history...
114
        // Gestion des autres caractères.
115
        $find = ['€', '‘', '$', '£', '`', '"', '#'];
116
        $replace = ['E', '', 'USD', 'GBP', '', ' ', ''];
117
        $contenu = str_replace($find, $replace, $contenu);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $contenu. This often makes code more readable.
Loading history...
118
        $contenu = str_replace(['  ', '   '], ' ', $contenu);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $contenu. This often makes code more readable.
Loading history...
119
        $out = [];
120
        preg_match_all("#[^0-9a-zA-Zéèà\,\!\?\'\(\)\_\%\/\+\=\:\.\-\@\;\<\>\*\ ]#u", $contenu, $out); // Suppresion du caractère \&
121
        $outTmp = array_filter($out[0]);
122
        if (empty($outTmp)) {
123
            return $contenu;
124
        }
125
        foreach ($outTmp as $element) {
126
            $elementVide = empty($element) ? $element : iconv('UTF-8', 'ASCII//TRANSLIT', $element);
127
            $contenu = str_replace($element, $elementVide, $contenu);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $contenu. This often makes code more readable.
Loading history...
128
        }
129
130
        return $contenu;
131
    }
132
133
    public function getSupport($api, $version)
134
    {
135
        return strtolower($api) == 'buzzexpert';
136
    }
137
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
138