FlashAlertsHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A renderFlashAlerts() 0 9 1
A resolveOptions() 0 6 1
1
<?php
2
/**
3
 * FlashAlertsHelper.php
4
 * Definition of class FlashAlertsHelper
5
 *
6
 * Created 16/12/14 18:50
7
 *
8
 * @author Rasanga Perera <[email protected]>
9
 * @copyright (c) 2014, The MIT License (MIT)
10
 */
11
12
namespace Ras\Bundle\FlashAlertBundle\Templating\Helper;
13
14
15
use Ras\Bundle\FlashAlertBundle\Model\AlertPublisher;
16
use Symfony\Component\Console\Helper\Helper;
17
use Symfony\Component\Templating\EngineInterface;
18
19
class FlashAlertsHelper extends Helper
20
{
21
    /**
22
     * @var EngineInterface
23
     */
24
    private $templating;
25
26
    /**
27
     * @var AlertPublisher
28
     */
29
    private $alertPublisher;
30
31
    /**
32
     * @var array
33
     */
34
    private $options = array();
35
36
    /**
37
     * @param \Symfony\Component\Templating\EngineInterface $templating
38
     * @param \Ras\Bundle\FlashAlertBundle\Model\AlertPublisher $alertPublisher
39
     * @param array $options
40
     */
41
    public function __construct(EngineInterface $templating, AlertPublisher $alertPublisher, array $options)
42
    {
43
        $this->templating  = $templating;
44
        $this->alertPublisher = $alertPublisher;
45
        $this->options = $options;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function getName()
52
    {
53
        return 'ras_flash_alert_helper';
54
    }
55
56
    /**
57
     * Returns the HTML for the flashAlerts
58
     *
59
     * @param array $options
60
     * @return string A HTML string
61
     */
62
    public function renderFlashAlerts(array $options = array())
63
    {
64
        $options = $this->resolveOptions($options);
65
66
        return $this->templating->render(
67
            $options['template'],
68
            $options
69
        );
70
    }
71
72
    /**
73
     * Merges user-supplied options from the view
74
     * with base config values
75
     *
76
     * @param array $options
77
     * @return array
78
     */
79
    private function resolveOptions(array $options = array())
80
    {
81
        $this->options['alertPublisher'] = $this->alertPublisher;
82
83
        return array_merge($this->options, $options);
84
    }
85
}