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

KlineResponse::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 16
rs 9.9332
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Derivatives\PublicChannels\Kline\Entity;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Interfaces\ICollectionInterface;
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
    private string $topic;
13
    private string $type;
14
    private \DateTime $timestamp;
15
    private ICollectionInterface $data;
16
17
    public function __construct(array $data)
18
    {
19
        $collection = new EntityCollection();
20
21
        $this->topic = $data['topic'];
22
        $this->type = $data['type'];
23
        $this->timestamp = DateTimeHelper::makeFromTimestamp($data['ts']);
24
25
        if (!empty($data['data'])) {
26
            if (!empty($data['data'])) {
27
                array_map(function ($item) use ($collection) {
28
                    $collection->push(ResponseDtoBuilder::make(KlineResponseItem::class, $item));
29
                }, $data['data']);
30
            }
31
        }
32
        $this->data = $collection;
33
    }
34
35
    public function getTopic(): string
36
    {
37
        return $this->topic;
38
    }
39
40
    public function getType(): string
41
    {
42
        return $this->type;
43
    }
44
45
    public function getTimestamp(): \DateTime
46
    {
47
        return $this->timestamp;
48
    }
49
50
    public function getData(): array
51
    {
52
        return $this->data->all();
53
    }
54
}
55
56
57