Completed
Push — master ( 4bb011...4b99be )
by Guillaume
13:23
created

OctosendHtmlRender   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 14 1
A renderMirror() 0 6 1
A renderPixel() 0 6 1
A renderLien() 0 15 3
A retournerLaChaine() 0 8 2
A getSupport() 0 4 2
1
<?php
2
3
namespace Starkerxp\CampaignBundle\Render;
4
5
class OctosendHtmlRender extends AbstractRender
6
{
7
    public function render()
8
    {
9
        // Gestion des liens mirror
10
        $contenu = $this->renderMirror($this->contenu);
11
        // Gestion des liens pixels
12
        $contenu = $this->renderPixel($contenu);
13
        // Gestion des liens de desinscriptions.
14
        $contenu = $this->renderLien("unsub", $contenu);
15
        // Gestion des liens click:http://
16
        $contenu = $this->renderLien("click", $contenu);
17
        $contenu = str_replace('  ', ' ', str_replace('  ', ' ', $contenu));
18
19
        return $contenu;
20
    }
21
22
    protected function renderMirror($contenu)
23
    {
24
        $contenuReplace = preg_replace('/\[\{\@mirror\}\]/', '{{mirror}}', $contenu);
25
26
        return $contenuReplace;
27
    }
28
29
    protected function renderPixel($contenu)
30
    {
31
        $contenuReplace = preg_replace('/\[\{\@pixel\}\]/', '{{pixel}}', $contenu);
32
33
        return $contenuReplace;
34
    }
35
36
    private function renderLien($type, $contenu)
37
    {
38
        $arrayContenu = [];
39
        preg_match_all("#<a data-id=\"".$type."\" target=\"__blank\" href=\"(.*?)\" style=\"(.*?)\">(.*?)</a>#", $contenu, $arrayContenu);
40
        if (empty($arrayContenu[0])) {
41
            return $contenu;
42
        }
43
        foreach ($arrayContenu[0] as $key => $chaineARemplacer) {
44
            $chaineOctoSend = $this->retournerLaChaine($type, $arrayContenu[1][$key], $arrayContenu[3][$key], $arrayContenu[2][$key]);
45
            $contenu = str_replace($chaineARemplacer, $chaineOctoSend, $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...
46
        }
47
48
        return $contenu;
49
50
    }
51
52
    protected function retournerLaChaine($type, $lien, $texte, $style = null)
53
    {
54
        if ($type == "unsub") {
55
            return "<a href='{{unsubscribe:".$lien."}}' style='".$style."' title='Désinscription'>".$texte.'</a>';
56
        }
57
58
        return "<a href='{{click:".$lien."}}' style='".$style."'>".$texte.'</a>';;
59
    }
60
61
    public function getSupport($api, $version)
62
    {
63
        return $api == 'octosend' && $version == 'html';
64
    }
65
66
67
}
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...
68