GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( bb8806...1a2c53 )
by Marc
10s
created

AbstractChart   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 275
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.81%

Importance

Changes 9
Bugs 0 Features 2
Metric Value
wmc 39
c 9
b 0
f 2
lcom 1
cbo 2
dl 0
loc 275
ccs 91
cts 97
cp 0.9381
rs 8.2857

19 Methods

Rating   Name   Duplication   Size   Complexity  
render() 0 1 ?
A initChartOption() 0 4 1
A initArrayOption() 0 4 1
A __construct() 0 16 3
A __call() 0 6 1
A renderWithJavascriptCallback() 0 14 3
A renderArrayWithCallback() 0 11 2
A renderObjectWithCallback() 0 11 2
A renderEngine() 0 8 3
A renderColors() 0 8 2
A renderCredits() 0 8 2
A renderSubtitle() 0 8 2
A renderTitle() 0 8 2
A renderXAxis() 0 10 3
A renderYAxis() 0 10 3
A renderOptions() 0 13 3
A renderGlobal() 0 8 2
A renderLang() 0 8 2
A renderScrollbar() 0 8 2
1
<?php
2
3
namespace Ob\HighchartsBundle\Highcharts;
4
5
use Zend\Json\Json;
6
7
abstract class AbstractChart
8
{
9
    // Default options
10
    public $chart;
11
    public $colors;
12
    public $credits;
13
    public $global;
14
    public $labels;
15
    public $lang;
16
    public $legend;
17
    public $loading;
18
    public $plotOptions;
19
    public $rangeSelector;
20
    public $point;
21
    public $series;
22
    public $drilldown;
23
    public $subtitle;
24
    public $symbols;
25
    public $title;
26
    public $tooltip;
27
    public $xAxis;
28
    public $yAxis;
29
    public $exporting;
30
    public $navigation;
31
    public $pane;
32
    public $scrollbar;
33
34 69
    public function __construct()
35
    {
36 69
        $chartOptions = array('chart', 'credits', 'global', 'labels', 'lang', 'legend', 'loading', 'plotOptions',
37 69
            'rangeSelector', 'point', 'subtitle', 'title', 'tooltip', 'xAxis', 'yAxis', 'pane', 'exporting',
38 69
            'navigation', 'drilldown', 'scrollbar');
39
40 69
        foreach ($chartOptions as $option) {
41 69
            $this->initChartOption($option);
42 69
        }
43
44 69
        $arrayOptions = array('colors', 'series', 'symbols');
45
46 69
        foreach ($arrayOptions as $option) {
47 69
            $this->initArrayOption($option);
48 69
        }
49 69
    }
50
51
    abstract public function render();
52
53
    /**
54
     * @param string $name
55
     * @param mixed  $value
56
     *
57
     * @return $this
58
     */
59 3
    public function __call($name, $value)
60
    {
61 3
        $this->$name = $value;
62
63 3
        return $this;
64
    }
65
66
    /**
67
     * @param string $name
68
     */
69 69
    protected function initChartOption($name)
70
    {
71 69
        $this->{$name} = new ChartOption($name);
72 69
    }
73
74
    /**
75
     * @param string $name
76
     */
77 69
    protected function initArrayOption($name)
78
    {
79 69
        $this->{$name} = array();
80 69
    }
81
82
    /**
83
     * @param ChartOption|array $chartOption
84
     * @param string            $name
85
     *
86
     * @return string
87
     */
88 67
    protected function renderWithJavascriptCallback($chartOption, $name)
89
    {
90 67
        $result = "";
91
92 67
        if (gettype($chartOption) === 'array') {
93 67
            $result .= $this->renderArrayWithCallback($chartOption, $name);
94 67
        }
95
96 67
        if (gettype($chartOption) === 'object') {
97 67
            $result .= $this->renderObjectWithCallback($chartOption, $name);
98 67
        }
99
100 67
        return $result;
101
    }
102
103
    /**
104
     * @param array  $chartOption
105
     * @param string $name
106
     *
107
     * @return string
108
     */
109 67
    protected function renderArrayWithCallback($chartOption, $name)
110
    {
111 67
        $result = "";
112
113 67
        if (!empty($chartOption)) {
114
            // Zend\Json is used in place of json_encode to preserve JS anonymous functions
115 1
            $result .= $name . ": " . Json::encode($chartOption[0], false, array('enableJsonExprFinder' => true)) . ", \n";
116 1
        }
117
118 67
        return $result;
119
    }
120
121
    /**
122
     * @param ChartOption $chartOption
123
     * @param string      $name
124
     *
125
     * @return string
126
     */
127 67
    protected function renderObjectWithCallback($chartOption, $name)
128
    {
129 67
        $result = "";
130
131 67
        if (get_object_vars($chartOption)) {
132
            // Zend\Json is used in place of json_encode to preserve JS anonymous functions
133 47
            $result .= $name . ": " . Json::encode($chartOption, false, array('enableJsonExprFinder' => true)) . ",\n";
134 47
        }
135
136 67
        return $result;
137
    }
138
139
    /**
140
     * @param string $engine
141
     *
142
     * @return string
143
     */
144 67
    protected function renderEngine($engine)
145
    {
146 67
        if ($engine == 'mootools') {
147 2
            return 'window.addEvent(\'domready\', function () {';
148 66
        } elseif ($engine == 'jquery') {
149 65
            return "$(function () {";
150
        }
151 1
    }
152
153
    /**
154
     * @return string
155
     */
156 67
    protected function renderColors()
157
    {
158 67
        if (!empty($this->colors)) {
159 2
            return "colors: " . json_encode($this->colors) . ",\n";
160
        }
161
162 65
        return "";
163
    }
164
165
    /**
166
     * @return string
167
     */
168 67
    protected function renderCredits()
169
    {
170 67
        if (get_object_vars($this->credits->credits)) {
171 4
            return "credits: " . json_encode($this->credits->credits) . ",\n";
172
        }
173
174 63
        return "";
175
    }
176
177
    /**
178
     * @return string
179
     */
180 67
    protected function renderSubtitle()
181
    {
182 67
        if (get_object_vars($this->subtitle->subtitle)) {
183
            return "subtitle: " . json_encode($this->subtitle->subtitle) . ",\n";
184
        }
185
186 67
        return "";
187
    }
188
189
    /**
190
     * @return string
191
     */
192 67
    protected function renderTitle()
193
    {
194 67
        if (get_object_vars($this->title->title)) {
195
            return "title: " . json_encode($this->title->title) . ",\n";
196
        }
197
198 67
        return "";
199
    }
200
201
    /**
202
     * @return string
203
     */
204 67
    protected function renderXAxis()
205
    {
206 67
        if (gettype($this->xAxis) === 'array') {
207
            return $this->renderWithJavascriptCallback($this->xAxis, "xAxis");
208 67
        } elseif (gettype($this->xAxis) === 'object') {
209 67
            return $this->renderWithJavascriptCallback($this->xAxis->xAxis, "xAxis");
210
        }
211
212
        return "";
213
    }
214
215
    /**
216
     * @return string
217
     */
218 67
    protected function renderYAxis()
219
    {
220 67
        if (gettype($this->yAxis) === 'array') {
221
            return $this->renderWithJavascriptCallback($this->yAxis, "yAxis");
222 67
        } elseif (gettype($this->yAxis) === 'object') {
223 67
            return $this->renderWithJavascriptCallback($this->yAxis->yAxis, "yAxis");
224
        }
225
226
        return "";
227
    }
228
229
    /**
230
     * @return string
231
     */
232 67
    protected function renderOptions()
233
    {
234 67
        $result = "";
235
236 67
        if (get_object_vars($this->global->global) || get_object_vars($this->lang->lang)) {
237 5
            $result .= "\n    Highcharts.setOptions({";
238 5
            $result .= $this->renderGlobal();
239 5
            $result .= $this->renderLang();
240 5
            $result .= "    });\n";
241 5
        }
242
243 67
        return $result;
244
    }
245
246
    /**
247
     * @return string
248
     */
249 5
    protected function renderGlobal()
250
    {
251 5
        if (get_object_vars($this->global->global)) {
252 1
            return "global: " . json_encode($this->global->global) . ",\n";
253
        }
254
255 4
        return "";
256
    }
257
258
    /**
259
     * @return string
260
     */
261 5
    protected function renderLang()
262
    {
263 5
        if (get_object_vars($this->lang->lang)) {
264 4
            return "lang: " . json_encode($this->lang->lang) . ",\n";
265
        }
266
267 1
        return "";
268
    }
269
270
    /**
271
     * @return string
272
     */
273 67
    protected function renderScrollbar()
274
    {
275 67
        if (get_object_vars($this->scrollbar->scrollbar)) {
276 1
            return 'scrollbar: ' . json_encode($this->scrollbar->scrollbar) . ",\n";
277
        }
278
279 66
        return '';
280
    }
281
}
282