Completed
Pull Request — master (#4)
by Guillaume
02:36
created

AutopromoBannerScriptGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 32
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B generate() 0 24 3
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 = null)
16
    {
17
        if(is_null($id)) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
18
            // TODO throw exception
19
        }
20
21
        if (!$this->cache->isAutopromoBannerConfigured()) {
22
            return '';
23
        }
24
25
        $url = $this->cache->getAutopromoBannerUrl();
26
        $script = $this->cache->getAutopromoBannerScript();
27
28
        $script = <<<EOS
29
(function (a,d){var s,t,cs,ds,dd;s=d.createElement('script');cs=d.currentScript;
30
    ds=d.createElement('span');ds.id=Math.random().toString(36).substring(7);
31
    dd=cs.parentNode.insertBefore(ds,cs);
32
    s.src=a;s.async=1;s.setAttribute('data-dd',ds.id);s.setAttribute('data-id',$id);
33
    t=d.getElementsByTagName('script')[0];t.parentNode.insertBefore(s,t);})
34
("https://$url/$script.js", document);
35
EOS;
36
37
        return $script;
38
    }
39
}
40