GraphicalData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addData() 0 4 1
A addValue() 0 8 2
A export() 0 10 2
1
<?php
2
/**
3
 *
4
 */
5
6
/**
7
 * GraphicalData class
8
 *
9
 * @author Laurent De Coninck <[email protected]>
10
 */
11
class GraphicalData
12
{
13
14
    /**
15
     * @var YearGraphicalData[]
16
     */
17
    private $data;
18
19
    /**
20
     * GraphicalData constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->data = [];
25
    }
26
27
    /**
28
     * @param YearGraphicalData $pieceData
29
     */
30
    public function addData(YearGraphicalData $pieceData)
31
    {
32
        $this->data[$pieceData->getYear()] = $pieceData;
33
    }
34
35
    /**
36
     * @param int            $year
37
     * @param GraphicalValue $value
38
     *
39
     * @throws Exception
40
     */
41
    public function addValue($year, GraphicalValue $value)
42
    {
43
        if(!isset($this->data[$year])){
44
            throw new \Exception("Year is not defined");
45
        }
46
47
        $this->data[$year]->addGraphicalValue($value);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function export()
54
    {
55
        $result = [];
56
57
        foreach($this->data as $year){
58
            $result[] = $year->export();
59
        }
60
61
        return $result;
62
    }
63
64
}