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

ScriptExtension::generateAutopromoBannerScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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