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

BooktickerResponse   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 70
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 3
A getTopic() 0 3 1
A getRequestTimestamp() 0 3 1
A getType() 0 3 1
A getData() 0 3 1
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Spot\PublicChannels\Bookticker\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 BooktickerResponse extends AbstractResponse
11
{
12
    /**
13
     * Topic name
14
     * @var string
15
     */
16
    private string $topic;
17
18
    /**
19
     * The timestamp (ms) 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
30
    private EntityCollection $data;
31
32
33
    public function __construct(array $data)
34
    {
35
        $collection = new EntityCollection();
36
37
        $this->topic = $data['topic'];
38
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($data['ts']);
39
        $this->type = $data['type'];
40
41
        if (!empty($data['data'])) {
42
            
43
            $data['data'] = isset($data['data'][0]) ? $data['data'] : [$data['data']];
44
45
            array_map(function ($item) use ($collection) {
46
                $collection->push(ResponseDtoBuilder::make(BoocktickerResponseItem::class, $item));
47
            }, $data['data']);
48
        }
49
50
        $this->data = $collection;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getTopic(): string
57
    {
58
        return $this->topic;
59
    }
60
61
    /**
62
     * @return \DateTime
63
     */
64
    public function getRequestTimestamp(): \DateTime
65
    {
66
        return $this->requestTimestamp;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getType(): string
73
    {
74
        return $this->type;
75
    }
76
77
    public function getData(): array
78
    {
79
        return $this->data->all();
80
    }
81
}
82