Conditions | 8 |
Paths | 23 |
Total Lines | 45 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | public function draw(Data $data, $dataName) |
||
18 | { |
||
19 | $arrayToDataTable = $data->getArrayToDataTable(); |
||
20 | |||
21 | if (!$arrayToDataTable) { |
||
|
|||
22 | throw new GoogleChartsException( |
||
23 | 'There is no data for chart. Use method setArrayToDataTable() to provide data.' |
||
24 | ); |
||
25 | } |
||
26 | |||
27 | $js = "var $dataName = new google.visualization.arrayToDataTable(["; |
||
28 | |||
29 | end($arrayToDataTable); |
||
30 | $lastKeyRow = key($arrayToDataTable); |
||
31 | foreach ($data->getArrayToDataTable() as $keyRow => $row) { |
||
32 | $js .= '['; |
||
33 | |||
34 | end($row); |
||
35 | $lastKeyValue = key($row); |
||
36 | foreach ($row as $key => $value) { |
||
37 | if ($value instanceof \DateTime) { |
||
38 | $js .= 'new Date('.$value->format('Y').', '.($value->format('n') - 1).', '. |
||
39 | $value->format('d').', '.$value->format('H').', '.$value->format('i').', '. |
||
40 | $value->format('s').')'; |
||
41 | } else { |
||
42 | $js .= json_encode($value); |
||
43 | } |
||
44 | |||
45 | if ($key != $lastKeyValue) { |
||
46 | $js .= ', '; |
||
47 | } |
||
48 | } |
||
49 | unset($value); |
||
50 | $js .= ']'; |
||
51 | |||
52 | if ($keyRow != $lastKeyRow) { |
||
53 | $js .= ', '; |
||
54 | } |
||
55 | } |
||
56 | unset($row); |
||
57 | |||
58 | $data->isFirstRowIsData() ? $js .= '], true);' : $js .= '], false);'; |
||
59 | |||
60 | return $js; |
||
61 | } |
||
62 | } |
||
63 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.