Passed
Pull Request — master (#26)
by Christophe
03:34
created

Events::getListeners()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
crap 1
1
<?php
2
3
namespace CMEN\GoogleChartsBundle\GoogleCharts;
4
5
use CMEN\GoogleChartsBundle\Exception\GoogleChartsException;
6
7
/**
8
 * @author Christophe Meneses
9
 */
10
class Events
11
{
12
    /**
13
     * @var Listener[]
14
     */
15
    protected $listeners;
16
17
    /**
18
     * @var Chart
19
     */
20
    protected $chart;
21
22
    /**
23
     * Events constructor.
24
     *
25
     * @param Chart $chart
26
     */
27 12
    public function __construct(Chart $chart)
28
    {
29 12
        $this->listeners = [];
30 12
        $this->chart = $chart;
31 12
    }
32
33
    /**
34
     * Adds a listener.
35
     *
36
     * @param string $type         Type of event
37
     * @param string $functionName Name of Javascript function
38
     */
39 3
    public function addListener($type, $functionName)
40
    {
41 3
        if (!in_array($type, $this->chart->getAvailableEventTypes())) {
42 2
            throw new GoogleChartsException("$type event is not available for this type of chart.");
43
        }
44
45 1
        $this->listeners[] = new Listener($type, $functionName);
46 1
    }
47
48
    /**
49
     * @return Listener[]
50
     */
51 4
    public function getListeners()
52 1
    {
53 4
        return $this->listeners;
54
    }
55
}
56