Completed
Pull Request — master (#4)
by Guillaume
03:46
created

AutopromoBannerScriptGenerator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 20 2
1
<?php
2
3
namespace Dekalee\AdbackAnalytics\Generator;
4
5
/**
6
 * Class AutopromoBannerScriptGenerator
7
 */
8
class AutopromoBannerScriptGenerator extends AbstractScriptGenerator implements ScriptGeneratorInterface
9
{
10
    /**
11
     * @param int $id
12
     *
13
     * @return string
14
     */
15
    public function generate($id)
16
    {
17
        if (!$this->cache->isAutopromoBannerConfigured()) {
18
            return '';
19
        }
20
21
        $url = $this->cache->getAutopromoBannerUrl();
22
        $script = $this->cache->getAutopromoBannerScript();
23
24
        $script = <<<EOS
25
(function (a,d){var s,t,cs,ds,dd;s=d.createElement('script');cs=d.currentScript;
26
    ds=d.createElement('span');ds.id=Math.random().toString(36).substring(7);
27
    dd=cs.parentNode.insertBefore(ds,cs);
28
    s.src=a;s.async=1;s.setAttribute('data-dd',ds.id);s.setAttribute('data-id',$id);
29
    t=d.getElementsByTagName('script')[0];t.parentNode.insertBefore(s,t);})
30
("https://$url/$script.js", document);
31
EOS;
32
33
        return $script;
34
    }
35
}
36