Completed
Push — master ( 110a17...f6145a )
by Christophe
03:27
created

ColumnChartTest::setUp()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 302
Code Lines 266

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 302
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 266
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace CMEN\GoogleChartsBundle\Tests\Charts;
4
5
use CMEN\GoogleChartsBundle\GoogleCharts\Charts\ColumnChart;
6
use CMEN\GoogleChartsBundle\GoogleCharts\Options\Trendlines;
7
use CMEN\GoogleChartsBundle\GoogleCharts\Options\VAxis;
8
9
/**
10
 * Class ColumnChartTest
11
 *
12
 * @author Christophe Meneses
13
 */
14
class ColumnChartTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * @var ColumnChart
18
     */
19
    private $chart;
20
21
    /**
22
     * @inheritdoc
23
     */
24
    protected function setUp()
25
    {
26
        $this->chart = new ColumnChart();
27
        $this->chart->setElementID('div-chart')
28
            ->getData()->setArrayToDataTable([
29
                ['Time of Day', 'Motivation Level', ['role' => 'annotation'], 'Energy Level', ['role' => 'annotation']],
30
                [['v' => [8, 0, 0], 'f' => '8 am'],  1, '1', 0.25, '0.2'],
31
                [['v' => [9, 0, 0], 'f' => '9 am'],  2, '2',  0.5, '0.5'],
32
                [['v' => [10, 0, 0], 'f' => '10 am'], 3, '3',    1,  '1'],
33
                [['v' => [11, 0, 0], 'f' => '11 am'], 4, '4', 2.25,  '2'],
34
                [['v' => [12, 0, 0], 'f' => '12 am'], 5, '5', 2.25,  '2'],
35
                [['v' => [13, 0, 0], 'f' => '1 pm'],  6, '6',    3,  '3'],
36
                [['v' => [14, 0, 0], 'f' => '2 pm'],  7, '7', 3.25,  '3'],
37
                [['v' => [15, 0, 0], 'f' => '3 pm'],  8, '8',    5,  '5'],
38
                [['v' => [16, 0, 0], 'f' => '4 pm'],  9, '9',  6.5,  '6'],
39
                [['v' => [17, 0, 0], 'f' => '5 pm'], 10, '10',  10, '10']
40
            ]);
41
42
        $this->chart->getOptions()->getAnimation()
43
            ->setDuration(1000)
44
            ->setEasing('in')
45
            ->setStartup(true);
46
47
        $this->chart->getOptions()->getAnnotations()
48
            ->setAlwaysOutside(true)
49
            ->getBoxStyle()
50
                ->setStroke('#888')
51
                ->setStrokeWidth(1)
52
                ->setRx(10)
53
                ->setRy(10);
54
        $this->chart->getOptions()->getAnnotations()
55
            ->getDatum()
56
                ->setStyle('point')
57
                ->getStem()
58
                    ->setColor('black')
59
                    ->setLength(12);
60
        $this->chart->getOptions()->getAnnotations()
61
            ->getDomain()
62
                ->setStyle('point')
63
                ->getStem()
64
                    ->setColor('black')
65
                    ->setLength(5);
66
        $this->chart->getOptions()->getAnnotations()
67
            ->setHighContrast(true);
68
        $this->chart->getOptions()->getAnnotations()
69
            ->getStem()
70
                ->setColor('black')
71
                ->setLength(5);
72
        $this->chart->getOptions()->getAnnotations()
73
            ->setStyle('point');
74
        $this->chart->getOptions()->getAnnotations()
75
            ->getTextStyle()
76
                ->setFontName('Times-Roman')
77
                ->setFontSize(18)
78
                ->setBold(true)
79
                ->setItalic(true)
80
                ->setColor('#871b47')
81
                ->setAuraColor('#d799ae')
82
                ->setOpacity(0.8);
83
84
        $this->chart->getOptions()->setAxisTitlesPosition('out');
85
86
        //$this->chart->getOptions()->setBackgroundColor('red');
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
87
        $this->chart->getOptions()->getBackgroundColor()
88
            ->setStroke('#666')
89
            ->setStrokeWidth(0)
90
            ->setFill('white');
91
92
        $this->chart->getOptions()->getBar()->setGroupWidth('61.8%');
93
94
        $this->chart->getOptions()->getChartArea()
95
            //->setBackgroundColor('black')
96
            ->getBackgroundColor()
97
                ->setStroke('black')
98
                ->setStrokeWidth(1);
99
        $this->chart->getOptions()->getChartArea()
100
            ->setLeft('auto')
101
            ->setTop('auto')
102
            ->setWidth('auto')
103
            ->setHeight('auto');
104
105
        $this->chart->getOptions()->setColors(['red','#004411']);
106
107
        $this->chart->getOptions()->setDataOpacity(1.0);
108
109
        $this->chart->getOptions()->setEnableInteractivity(true);
110
111
        $this->chart->getOptions()->getExplorer()
112
            ->setActions(['dragToPan', 'rightClickToReset'])
113
            ->setAxis('vertical')
114
            ->setKeepInBounds(false)
115
            ->setMaxZoomIn(0.25)
116
            ->setMaxZoomOut(4)
117
            ->setZoomDelta(1.5);
118
119
        $this->chart->getOptions()->setFocusTarget('datum');
120
121
        $this->chart->getOptions()->setFontSize(12);
122
123
        $this->chart->getOptions()->setFontName('Arial');
124
125
        $this->chart->getOptions()->setForceIFrame(false);
126
127
        $this->chart->getOptions()->getHAxis()
128
            ->setBaseline(5)
129
            ->setBaselineColor('black')
130
            ->setDirection(1)
131
            ->setFormat('decimal')
132
            ->getGridlines()
133
                ->setColor('#CCC')
134
                ->setCount(5);
135
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
136
            ->getYears()->setFormat('yyyy');
137
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
138
            ->getMonths()->setFormat('M');
139
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
140
            ->getDays()->setFormat('d');
141
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
142
            ->getHours()->setFormat('H');
143
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
144
            ->getMinutes()->setFormat('i');
145
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
146
            ->getSeconds()->setFormat('s');
147
        $this->chart->getOptions()->getHAxis()->getGridlines()->getUnits()
148
            ->getMilliseconds()->setFormat('u');
149
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()
150
            ->setColor('black')
151
            ->setCount(0);
152
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
153
            ->getYears()->setFormat('yyyy');
154
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
155
            ->getMonths()->setFormat('M');
156
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
157
            ->getDays()->setFormat('d');
158
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
159
            ->getHours()->setFormat('H');
160
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
161
            ->getMinutes()->setFormat('i');
162
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
163
            ->getSeconds()->setFormat('s');
164
        $this->chart->getOptions()->getHAxis()->getMinorGridlines()->getUnits()
165
            ->getMilliseconds()->setFormat('u');
166
        $this->chart->getOptions()->getHAxis()
167
            ->setLogScale(false)
168
            ->setScaleType('log')
169
            ->setTextPosition('out')
170
            ->getTextStyle()
171
                ->setFontName('Times-Roman')
172
                ->setFontSize(12)
173
                ->setBold(true)
174
                ->setItalic(true)
175
                ->setColor('black');
176
        $this->chart->getOptions()->getHAxis()
177
            ->setTicks([5,10,15,20])
178
            ->setTitle('title')
179
            ->getTitleTextStyle()
180
                ->setColor('black')
181
                ->setFontName('Arial')
182
                ->setFontSize(18)
183
                ->setBold(true)
184
                ->setItalic(true);
185
        $this->chart->getOptions()->getHAxis()
186
            ->setAllowContainerBoundaryTextCufoff(false)
187
            ->setSlantedText(false)
188
            ->setSlantedTextAngle(30)
189
            ->setMaxAlternation(2)
190
            ->setMaxTextLines(5)
191
            ->setMinTextSpacing(5)
192
            ->setShowTextEvery(1)
193
            ->setMaxValue(100)
194
            ->setMinValue(1)
195
            ->setViewWindowMode('pretty');
196
        $this->chart->getOptions()->getHAxis()
197
            ->getViewWindow()
198
                ->setMax(100)
199
                ->setMin(1);
200
201
        $this->chart->getOptions()->setHeight(500);
202
203
        $this->chart->getOptions()->setIsStacked(false);
204
205
        $this->chart->getOptions()->getLegend()
206
            ->setPosition('right')
207
            ->setAlignment('start')
208
            ->getTextStyle()
209
                ->setColor('black')
210
                ->setFontName('Arial')
211
                ->setFontSize(10)
212
                ->setBold(false)
213
                ->setItalic(false);
214
215
        $this->chart->getOptions()->setOrientation('horizontal');
216
217
        $this->chart->getOptions()->setReverseCategories(false);
218
219
        $this->chart->getOptions()->setSeries([
0 ignored issues
show
Documentation introduced by
array(array('color' => '...bleInLegend' => false)) is of type array<integer,array,{"0"...Legend\":\"false\"}>"}>, but the function expects a array<integer,object<CME...Charts\Options\Series>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
220
            ['color' => 'black', 'visibleInLegend' => false], [], [],
221
            ['color' => 'red', 'visibleInLegend' => false]
222
        ]);
223
224
        $this->chart->getOptions()->setTheme('maximized');
225
226
        $this->chart->getOptions()->setTitle('Title');
227
228
        $this->chart->getOptions()->setTitlePosition('out');
229
230
        $this->chart->getOptions()->getTitleTextStyle()
231
            ->setColor('black')
232
            ->setFontName('Arial')
233
            ->setFontSize(18)
234
            ->setBold(false)
235
            ->setItalic(false);
236
237
        $this->chart->getOptions()->getTooltip()
238
            ->setIgnoreBounds(false)
239
            ->setIsHtml(false)
240
            ->setShowColorCode(false)
241
            ->setTrigger('focus')
242
            ->getTextStyle()
243
                ->setColor('black')
244
                ->setFontName('Arial')
245
                ->setFontSize(10)
246
                ->setBold(false)
247
                ->setItalic(false);
248
249
        $this->chart->getOptions()->setTrendlines([new Trendlines(), new Trendlines()]);
250
251
        $vAxis1 = new VAxis();
252
        $vAxis1->setTitle('v1');
253
        $vAxis2 = new VAxis();
254
        $vAxis2->setTitle('v2');
255
        $this->chart->getOptions()->setVAxes([$vAxis1, $vAxis2]);
256
257
        $this->chart->getOptions()->getVAxis()
258
            ->setBaseline(5)
259
            ->setBaselineColor('black')
260
            ->setDirection(1)
261
            ->setFormat('decimal')
262
            ->getGridlines()
263
                ->setColor('#CCC')
264
                ->setCount(5);
265
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
266
            ->getYears()->setFormat('yyyy');
267
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
268
            ->getMonths()->setFormat('M');
269
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
270
            ->getDays()->setFormat('d');
271
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
272
            ->getHours()->setFormat('H');
273
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
274
            ->getMinutes()->setFormat('i');
275
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
276
            ->getSeconds()->setFormat('s');
277
        $this->chart->getOptions()->getVAxis()->getGridlines()->getUnits()
278
            ->getMilliseconds()->setFormat('u');
279
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()
280
            ->setColor('black')
281
            ->setCount(0);
282
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
283
            ->getYears()->setFormat('yyyy');
284
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
285
            ->getMonths()->setFormat('M');
286
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
287
            ->getDays()->setFormat('d');
288
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
289
            ->getHours()->setFormat('H');
290
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
291
            ->getMinutes()->setFormat('i');
292
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
293
            ->getSeconds()->setFormat('s');
294
        $this->chart->getOptions()->getVAxis()->getMinorGridlines()->getUnits()
295
            ->getMilliseconds()->setFormat('u');
296
        $this->chart->getOptions()->getVAxis()
297
            ->setLogScale(false)
298
            ->setScaleType('log')
299
            ->setTextPosition('out')
300
            ->getTextStyle()
301
                ->setFontName('Times-Roman')
302
                ->setFontSize(12)
303
                ->setBold(true)
304
                ->setItalic(true)
305
                ->setColor('black');
306
        $this->chart->getOptions()->getVAxis()
307
            ->setTicks([5,10,15,20])
308
            ->setTitle('title')
309
            ->getTitleTextStyle()
310
                ->setColor('black')
311
                ->setFontName('Arial')
312
                ->setFontSize(18)
313
                ->setBold(true)
314
                ->setItalic(true);
315
        $this->chart->getOptions()->getVAxis()
316
            ->setMaxValue(100)
317
            ->setMinValue(1)
318
            ->setViewWindowMode('pretty');
319
        $this->chart->getOptions()->getVAxis()
320
            ->getViewWindow()
321
                ->setMax(100)
322
                ->setMin(1);
323
324
        $this->chart->getOptions()->setWidth(700);
325
    }
326
327
    public function testJsColumnChart()
328
    {
329
        $js = $this->chart->startDraw() . $this->chart->endDraw();
330
331
        $this->assertContains('{"animation":{"startup":true,"duration":1000,"easing":"in"},"annotations":{"alwaysOutside":true,"boxStyle":{"stroke":"#888","strokeWidth":1,"rx":10,"ry":10},"datum":{"stem":{"color":"black","length":12},"style":"point"},"domain":{"stem":{"color":"black","length":5},"style":"point"},"highContrast":true,"stem":{"color":"black","length":5},"style":"point","textStyle":{"auraColor":"#d799ae","opacity":0.8,"bold":true,"italic":true,"color":"#871b47","fontName":"Times-Roman","fontSize":18}},"bar":{"groupWidth":"61.8%"},"dataOpacity":1,"explorer":{"actions":["dragToPan","rightClickToReset"],"axis":"vertical","keepInBounds":false,"maxZoomIn":0.25,"maxZoomOut":4,"zoomDelta":1.5},"focusTarget":"datum","hAxis":{"allowContainerBoundaryTextCufoff":false,"slantedText":false,"slantedTextAngle":30,"maxAlternation":2,"maxTextLines":5,"minTextSpacing":5,"showTextEvery":1,"baseline":5,"baselineColor":"black","direction":1,"format":"decimal","logScale":false,"scaleType":"log","maxValue":100,"minValue":1,"ticks":[5,10,15,20],"gridlines":{"color":"#CCC","count":5,"units":{"years":{"format":"yyyy"},"months":{"format":"M"},"days":{"format":"d"},"hours":{"format":"H"},"minutes":{"format":"i"},"seconds":{"format":"s"},"milliseconds":{"format":"u"}}},"minorGridlines":{"color":"black","count":0,"units":{"years":{"format":"yyyy"},"months":{"format":"M"},"days":{"format":"d"},"hours":{"format":"H"},"minutes":{"format":"i"},"seconds":{"format":"s"},"milliseconds":{"format":"u"}}},"textPosition":"out","textStyle":{"bold":true,"italic":true,"color":"black","fontName":"Times-Roman","fontSize":12},"title":"title","titleTextStyle":{"color":"black","fontName":"Arial","fontSize":18,"bold":true,"italic":true},"viewWindow":{"max":100,"min":1},"viewWindowMode":"pretty"},"isStacked":false,"legend":{"alignment":"start","position":"right","textStyle":{"bold":false,"italic":false,"color":"black","fontName":"Arial","fontSize":10}},"orientation":"horizontal","reverseCategories":false,"tooltip":{"ignoreBounds":false,"showColorCode":false,"textStyle":{"bold":false,"italic":false,"color":"black","fontName":"Arial","fontSize":10},"trigger":"focus","isHtml":false},"vAxes":[{"title":"v1"},{"title":"v2"}],"axisTitlesPosition":"out","series":{"0":{"color":"black","visibleInLegend":false},"3":{"color":"red","visibleInLegend":false}},"theme":"maximized","titlePosition":"out","vAxis":{"baseline":5,"baselineColor":"black","direction":1,"format":"decimal","gridlines":{"color":"#CCC","count":5,"units":{"years":{"format":"yyyy"},"months":{"format":"M"},"days":{"format":"d"},"hours":{"format":"H"},"minutes":{"format":"i"},"seconds":{"format":"s"},"milliseconds":{"format":"u"}}},"minorGridlines":{"color":"black","count":0,"units":{"years":{"format":"yyyy"},"months":{"format":"M"},"days":{"format":"d"},"hours":{"format":"H"},"minutes":{"format":"i"},"seconds":{"format":"s"},"milliseconds":{"format":"u"}}},"logScale":false,"scaleType":"log","textPosition":"out","textStyle":{"bold":true,"italic":true,"color":"black","fontName":"Times-Roman","fontSize":12},"ticks":[5,10,15,20],"title":"title","titleTextStyle":{"color":"black","fontName":"Arial","fontSize":18,"bold":true,"italic":true},"maxValue":100,"minValue":1,"viewWindowMode":"pretty","viewWindow":{"max":100,"min":1}},"backgroundColor":{"fill":"white","stroke":"#666","strokeWidth":0},"chartArea":{"backgroundColor":{"stroke":"black","strokeWidth":1},"height":"auto","left":"auto","top":"auto","width":"auto"},"colors":["red","#004411"],"fontSize":12,"fontName":"Arial","title":"Title","titleTextStyle":{"color":"black","fontName":"Arial","fontSize":18,"bold":false,"italic":false},"enableInteractivity":true,"forceIFrame":false,"height":500,"width":700}', $js);
332
    }
333
}
334