Events   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 30
ccs 8
cts 8
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addListener() 0 7 2
A getListeners() 0 3 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 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