AnalyticsScriptGenerator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
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 25
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 19 2
1
<?php
2
3
namespace Dekalee\AdbackAnalytics\Generator;
4
5
/**
6
 * Class AnalyticsScriptGenerator
7
 */
8
class AnalyticsScriptGenerator extends AbstractScriptGenerator implements ScriptGeneratorInterface
9
{
10
    /**
11
     * @return string
12
     */
13
    public function generate()
14
    {
15
        if (!$this->cache->isAnalyticsConfigured()) {
16
            return '';
17
        }
18
19
        $url = $this->cache->getAnalyticsUrl();
20
        $script = $this->cache->getAnalyticsScript();
21
22
        $script = <<<EOS
23
(function (a,d){var s,t;s=d.createElement('script');
24
    s.src=a;s.async=1;
25
    t=d.getElementsByTagName('script')[0];
26
    t.parentNode.insertBefore(s,t);
27
})("https://$url/$script.js", document);
28
EOS;
29
30
        return $script;
31
    }
32
}
33