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

FlashAlertsHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 5
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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