Passed
Push — master ( db039c...4d8c20 )
by Dāvis
04:33
created

FlashAlertsHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A renderFlashAlerts() 0 5 1
A __construct() 0 8 1
A getName() 0 3 1
A resolveOptions() 0 5 1
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Helper;
4
5
use Sludio\HelperBundle\Script\Model\AlertPublisher;
6
use Symfony\Component\Console\Helper\Helper;
7
use Symfony\Component\Templating\EngineInterface;
8
9
class FlashAlertsHelper extends Helper
10
{
11
    private $templating;
12
    private $alertPublisher;
13
    private $options = [];
14
15
    public function __construct(EngineInterface $templating, AlertPublisher $alertPublisher, $template, $styles, $scripts)
16
    {
17
        $this->templating = $templating;
18
        $this->alertPublisher = $alertPublisher;
19
        $this->options = [
20
            'use_styles' => $styles,
21
            'use_scripts' => $scripts,
22
            'template' => $template
23
        ];
24
    }
25
26
    public function renderFlashAlerts(array $options = [])
27
    {
28
        $options = $this->resolveOptions($options);
29
30
        return $this->templating->render($options['template'], $options);
31
    }
32
33
    private function resolveOptions(array $options = [])
34
    {
35
        $this->options['alert_publisher'] = $this->alertPublisher;
36
37
        return array_merge($this->options, $options);
38
    }
39
40
    public function getName()
41
    {
42
        return 'sludio_helper.templating.alerts_helper';
43
    }
44
}
45