Completed
Push — master ( 4d353e...460f15 )
by Guillaume
12s
created

ScriptExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 2
cbo 2
dl 0
loc 50
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
     * @param int $id
43
     *
44
     * @return string
45
     */
46
    public function generateAutopromoBannerScript($id)
47
    {
48
        return sprintf('<script>%s</script>', $this->autopromoBannerGenerator->generate($id));
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getFunctions()
55
    {
56
        return [
57
            new \Twig_SimpleFunction('adback_generate_scripts', [$this, 'generateScripts'], ['is_safe' => ['html']]),
58
            new \Twig_SimpleFunction('adback_generate_autopromo_banner_script', [$this, 'generateAutopromoBannerScript'], ['is_safe' => ['html']]),
59
        ];
60
    }
61
}
62