Passed
Pull Request — master (#10)
by Vladislav
15:29 queued 07:37
created

KlineResponse::getRequestTimestamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Channels\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
use Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Bookticker\Entities\BoocktickerResponseItem;
10
11
class KlineResponse extends AbstractResponse
12
{
13
    /**
14
     * Topic name
15
     * @var string $topic
16
     */
17
    private string $topic;
18
19
    /**
20
     * The timestamp that message is sent out
21
     * @var \DateTime $requestTimestamp
22
     */
23
    private \DateTime $requestTimestamp;
24
25
    /**
26
     * Data type. snapshot
27
     * @var string $type
28
     */
29
    private string $type;
30
    private EntityCollection $data;
31
32
 
33
    public function __construct(array $data)
34
    {
35
        $collection = new EntityCollection();
36
37
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($data['ts']);
38
        $this->topic = $data['topic'];
39
        $this->type = $data['type'];
40
41
        if (!empty($data['data'])) {
42
            
43
            $data['data'] = array_is_list($data['data']) ? $data['data'] : [$data['data']];
0 ignored issues
show
Bug introduced by
The function array_is_list was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            $data['data'] = /** @scrutinizer ignore-call */ array_is_list($data['data']) ? $data['data'] : [$data['data']];
Loading history...
44
45
            array_map(function ($item) use ($collection) {
46
                $collection->push(ResponseDtoBuilder::make(KlineResponseItem::class, $item));
47
            }, $data['data']);
48
        }
49
50
        $this->data = $collection;
51
    }
52
53
    public function getTopic(): string
54
    {
55
        return $this->topic;
56
    }
57
58
    public function getRequestTimestamp(): \DateTime
59
    {
60
        return $this->requestTimestamp;
61
    }
62
63
    public function getType(): string
64
    {
65
        return $this->type;
66
    }
67
68
    public function getData(): array
69
    {
70
        return $this->data->all();
71
    }
72
}
73