Passed
Pull Request — master (#38)
by Christophe
05:14
created

Chart::getElementID()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace CMEN\GoogleChartsBundle\GoogleCharts;
4
5
use CMEN\GoogleChartsBundle\GoogleCharts\Options\ChartOptionsInterface;
6
7
/**
8
 * @author Christophe Meneses
9
 */
10
abstract class Chart
11
{
12
    /**
13
     * @var string|null
14
     */
15
    protected $elementID;
16
17
    /**
18
     * @var Data
19
     */
20
    protected $data;
21
22
    /**
23
     * @var ChartOptionsInterface
24
     */
25
    protected $options;
26
27
    /**
28
     * @var Events
29
     */
30
    protected $events;
31
32 13
    public function __construct()
33
    {
34 13
        $this->data = new Data();
35 13
        $this->events = new Events($this);
36 13
    }
37
38
    /**
39
     * Returns chart's name.
40
     *
41
     * @return string
42
     */
43 4
    public function getName()
44
    {
45 4
        if (null === $this->elementID) {
46
            return '';
47
        }
48
49 4
        return 'chart'.ucfirst($this->elementID);
50
    }
51
52
    /**
53
     * Returns data chart's name.
54
     *
55
     * @return string
56
     */
57 4
    public function getDataName()
58
    {
59 4
        return 'data'.ucfirst($this->getName());
60
    }
61
62
    /**
63
     * Returns options chart's name.
64
     *
65
     * @return string
66
     */
67 4
    public function getOptionsName()
68
    {
69 4
        return 'options'.ucfirst($this->getName());
70
    }
71
72
    /**
73
     * Returns the chart type.
74
     *
75
     * @return string
76
     */
77
    abstract public function getType();
78
79
    /**
80
     * Returns library used by chart.
81
     *
82
     * @return string
83
     */
84 4
    public function getLibrary()
85
    {
86 4
        return 'visualization';
87
    }
88
89
    /**
90
     * Returns the chart package.
91
     *
92
     * @return string
93
     */
94
    abstract public function getPackage();
95
96
    /**
97
     * Returns available event types.
98
     *
99
     * @return string[]
100
     */
101
    abstract public function getAvailableEventTypes();
102
103
    /**
104
     * Returns the instance options.
105
     *
106
     * @return ChartOptionsInterface
107
     */
108
    abstract public function getOptions();
109
110
    /**
111
     * Sets the instance Options.
112
     *
113
     * @param ChartOptionsInterface $options
114
     *
115
     * @return ChartOptionsInterface
116
     */
117
    abstract public function setOptions($options);
118
119
    /**
120
     * @param string $elementID
121
     *
122
     * @return $this
123
     */
124 4
    public function setElementID($elementID)
125
    {
126 4
        $this->elementID = $elementID;
127
128 4
        return $this;
129
    }
130
131
    /**
132
     * @return string|null
133
     */
134 5
    public function getElementID()
135
    {
136 5
        return $this->elementID;
137
    }
138
139
    /**
140
     * @return Data
141
     */
142 5
    public function getData()
143
    {
144 5
        return $this->data;
145
    }
146
147
    /**
148
     * @return Events
149
     */
150 4
    public function getEvents()
151
    {
152 4
        return $this->events;
153
    }
154
}
155