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

PublicTradeResponse::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
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 17
rs 9.9332
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Derivatives\PublicChannels\PublicTrade\Entities;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
6
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
7
use Carpenstar\ByBitAPI\Core\Interfaces\ICollectionInterface;
8
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
9
10
class PublicTradeResponse extends AbstractResponse
11
{
12
13
    private string $topic;
14
15
    private string $type;
16
17
    private \DateTime $createdAt;
18
19
    private ICollectionInterface $data;
20
21
22
    public function __construct(array $data)
23
    {
24
        $collection = new EntityCollection();
25
26
        $this->topic = $data['topic'];
27
        $this->type = $data['type'];
28
        $this->createdAt = DateTimeHelper::makeFromTimestamp($data['ts']);
29
30
        if (!empty($data['data'])) {
31
            if (!empty($data['data'])) {
32
                array_map(function ($item) use ($collection) {
33
                    $collection->push(ResponseDtoBuilder::make(PublicTradeResponseItem::class, $item));
34
                }, $data['data']);
35
            }
36
        }
37
        
38
        $this->data = $collection;
39
    }
40
41
    public function getTopic(): string
42
    {
43
        return $this->topic;
44
    }
45
46
    public function getType(): string
47
    {
48
        return $this->type;
49
    }
50
51
    public function getCreatedAt(): \DateTime
52
    {
53
        return $this->createdAt;
54
    }
55
56
    public function getData(): array
57
    {
58
        return $this->data->all();
59
    }
60
}
61