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

PublicTradeResponse::getData()   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\PublicTrade\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 PublicTradeResponse extends AbstractResponse
11
{
12
    /**
13
     * Topic name
14
     * @var string $topic
15
     */
16
    private string $topic;
17
18
    /**
19
     * The timestamp (ms) that message is sent out
20
     * @var \DateTime $requestTime
21
     */
22
    private \DateTime $requestTime;
23
24
    /**
25
     * Data type. snapshot
26
     * @var string $type
27
     */
28
    private string $type;
29
30
    private EntityCollection $data;
31
32
    public function __construct(array $data)
33
    {
34
        $this->topic = $data['topic'];
35
        $this->type = $data['type'];
36
        $this->requestTime = DateTimeHelper::makeFromTimestamp($data['ts']);
37
38
        $collection = new EntityCollection();
39
40
        if (!empty($data['data'])) {
41
            $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

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