ScriptExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 2
cbo 5
dl 0
loc 48
ccs 0
cts 24
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A generateScripts() 0 7 1
A generateAutopromoBannerScript() 0 4 1
A getFunctions() 0 7 1
1
<?php
2
3
namespace Dekalee\AdbackAnalyticsBundle\Twig;
4
5
use Dekalee\AdbackAnalytics\Generator\AnalyticsScriptGenerator;
6
use Dekalee\AdbackAnalytics\Generator\MessageScriptGenerator;
7
use Dekalee\AdbackAnalytics\Generator\AutopromoBannerScriptGenerator;
8
9
/**
10
 * Class ScriptExtension
11
 */
12
class ScriptExtension extends \Twig_Extension
13
{
14
    protected $analyticsGenerator;
15
    protected $messageGenerator;
16
    protected $autopromoBannerGenerator;
17
18
    /**
19
     * @param AnalyticsScriptGenerator          $analyticsScriptGenerator
20
     * @param MessageScriptGenerator            $messageScriptGenerator
21
     * @param AutopromoBannerScriptGenerator    $autopromoBannerScriptGenerator
22
     */
23
    public function __construct(AnalyticsScriptGenerator $analyticsScriptGenerator, MessageScriptGenerator $messageScriptGenerator, AutopromoBannerScriptGenerator $autopromoBannerScriptGenerator)
24
    {
25
        $this->analyticsGenerator = $analyticsScriptGenerator;
26
        $this->messageGenerator = $messageScriptGenerator;
27
        $this->autopromoBannerGenerator = $autopromoBannerScriptGenerator;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function generateScripts()
34
    {
35
        return sprintf('<script>%s</script><script>%s</script>',
36
            $this->analyticsGenerator->generate(),
37
            $this->messageGenerator->generate()
38
        );
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function generateAutopromoBannerScript()
45
    {
46
        return sprintf('<script>%s</script>', $this->autopromoBannerGenerator->generate());
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getFunctions()
53
    {
54
        return [
55
            new \Twig_SimpleFunction('adback_generate_scripts', [$this, 'generateScripts'], ['is_safe' => ['html']]),
56
            new \Twig_SimpleFunction('adback_generate_autopromo_banner_script', [$this, 'generateAutopromoBannerScript'], ['is_safe' => ['html']]),
57
        ];
58
    }
59
}
60