Passed
Push — master ( 8ca73d...2eaf19 )
by Vladislav
02:37 queued 15s
created

KlineResponse::getData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Spot\PublicChannels\Kline\Entities;
4
5
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
6
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
7
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
8
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
9
10
class KlineResponse extends AbstractResponse
11
{
12
    /**
13
     * Topic name
14
     * @var string $topic
15
     */
16
    private string $topic;
17
18
    /**
19
     * The timestamp that message is sent out
20
     * @var \DateTime $requestTimestamp
21
     */
22
    private \DateTime $requestTimestamp;
23
24
    /**
25
     * Data type. snapshot
26
     * @var string $type
27
     */
28
    private string $type;
29
    private EntityCollection $data;
30
31
 
32
    public function __construct(array $data)
33
    {
34
        $collection = new EntityCollection();
35
36
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($data['ts']);
37
        $this->topic = $data['topic'];
38
        $this->type = $data['type'];
39
40
        if (!empty($data['data'])) {
41
            
42
            $data['data'] = isset($data['data'][0]) ? $data['data'] : [$data['data']];
43
44
            array_map(function ($item) use ($collection) {
45
                $collection->push(ResponseDtoBuilder::make(KlineResponseItem::class, $item));
46
            }, $data['data']);
47
        }
48
49
        $this->data = $collection;
50
    }
51
52
    public function getTopic(): string
53
    {
54
        return $this->topic;
55
    }
56
57
    public function getRequestTimestamp(): \DateTime
58
    {
59
        return $this->requestTimestamp;
60
    }
61
62
    public function getType(): string
63
    {
64
        return $this->type;
65
    }
66
67
    public function getData(): array
68
    {
69
        return $this->data->all();
70
    }
71
}
72