Events::addListener()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
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 array $listeners;
16
17 13
    public function __construct(protected Chart $chart)
18
    {
19 13
        $this->listeners = [];
20
    }
21
22
    /**
23
     * @throws GoogleChartsException
24
     */
25 3
    public function addListener(string $type, string $functionName): void
26
    {
27 3
        if (!in_array($type, $this->chart->getAvailableEventTypes())) {
28 2
            throw new GoogleChartsException("$type event is not available for this type of chart.");
29
        }
30
31 1
        $this->listeners[] = new Listener($type, $functionName);
32
    }
33
34
    /**
35
     * @return Listener[]
36
     */
37 4
    public function getListeners(): array
38
    {
39 4
        return $this->listeners;
40
    }
41
}
42