GoogleChartDataset   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 52
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setData() 0 5 1
A convert() 0 10 2
A pack() 0 4 1
1
<?php
2
3
namespace Spiral\Statistics\Extract\Dataset;
4
5
use Spiral\Statistics\Extract\DatasetInterface;
6
use Spiral\Statistics\Extract\Events\Row;
7
8
class GoogleChartDataset implements DatasetInterface
9
{
10
    /** @var array */
11
    private $labels;
12
13
    /** @var array */
14
    private $data;
15
16
    /** @var array|Row[] */
17
    private $raw;
18
19
    /**
20
     * GoogleChartDataset constructor.
21
     *
22
     * @param array $labels
23
     */
24
    public function __construct(array $labels)
25
    {
26
        $this->labels = $labels;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function setData(array $data)
33
    {
34
        $this->raw = $data;
35
        $this->convert();
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    protected function convert()
42
    {
43
        foreach ($this->raw as $row) {
44
            $label = $row->getLabel();
45
            $row = array_values($row->getEvents());
46
            array_unshift($row, $label);
47
48
            $this->data[] = $row;
49
        }
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function pack(): array
56
    {
57
        return [$this->labels] + $this->data;
58
    }
59
}